Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding of equals method

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
goto (good use ;-) ) the java doc. See index for equals(. U will whole list.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic