aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding of equals method 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 "overriding of equals method" Watch "overriding of equals method" New topic
Author

overriding of equals method

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
in the following question,b1.equals(b2) is true because, the Boolean class overrides the 'equals' method of Object class.
Can anybody tell me what are the other classes which overrides the equals method, and produces such results.(Apart from String and Wrapper classes)
Question : What is written to the standard output as the result of executing the following statements?
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
Object obj1 = (Object)b1;
Object obj2 = (Object)b2;
if (obj1 == obj2)
if (obj1.equals(obj2))
System.out.println("a");
else
System.out.println("b");
else
if (obj1.equals(obj2))
System.out.println("c");
else
System.out.println("d");
Select the one right answer.
a) a
b) b
c) c
d) d
hemanshow
Greenhorn

Joined: Jun 26, 2000
Posts: 25
goto (good use ;-) ) the java doc. See index for equals(. U will whole list.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: overriding of equals method