permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals( ) explanation ? 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 "equals( ) explanation ?" Watch "equals( ) explanation ?" New topic
Author

equals( ) explanation ?

saied ims
Ranch Hand

Joined: Jun 21, 2005
Posts: 109
What two statements are true about properly overridden hashCode() and equals()methods?


C. hashCode() can always return the same value, regardless of the object that invoked it.sure

E. equals() can be true even if it�s comparing different objects. why???what's the meaning of this???

thanks

[ October 15, 2006: Message edited by: saied ims ]

(removed shout in title)
[ October 15, 2006: Message edited by: Barry Gaunt ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The definition of equals is up to the programmer. The only thing that you are required to do when you override the equals method is to return a boolean.
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
The job of equals() is to compare two different objects meaningfully. This means you can have 2 separate references to 2 different objects and if the 2 objects are same according to the definition provided by the programmer, equals() will return true.

The default implementation of equals() in Object returns true only if you have references to the same object. You are expected to override it so that it returns true even if you have two different objects that are semantically equivalent.
[ October 15, 2006: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
saied ims
Ranch Hand

Joined: Jun 21, 2005
Posts: 109
thanks all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equals( ) explanation ?
 
Similar Threads
LearnKey Bonus Exam question
What does your name mean?
HashMap and equals method overriding
Can't Understand... K&B Mock Exam
Why override equals() method ?