This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
1 try {
2 if ((new Object))(.equals((new Object()))) {
3 System.out.println("equal");
4 )else{
5 System.out.println("not equal");
6 }
7 }catch (Exception e) {
8 System.out.println("exception");
9 }
What is the result?


A. equal

B. not equal

C. exception

D. Compilation fails.
Kavitha Govindaraj
Greenhorn

Joined: May 27, 2004
Posts: 28
Hi
There are compilation errors in your code. The corrected version is



Upon execution this code will print not equal.


Thanks <br />Kavitha G <br />SCJP
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
The default implementation of equals() method in Object class returns 'true' only if the object is compared with itself, that is, as if the equality operator == had been used to compare aliases to the object.

In the given code Two different objects are created. Hence not equal.

Regards
Naresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception
 
Similar Threads
equals method for objects
what is the ouptut and how..
String again
Please Answer soon with explanation
explain this string method..