aspose file tools*
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 Spring in Action this week in the Spring 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
 
Don't get me started about those stupid light bulbs.
 
subject: Exception