This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hashcode()... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashcode()..." Watch "hashcode()..." New topic
Author

hashcode()...

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
In some questions he has given code for equals method for which he is asking us to select most appropiate hashcode method from given choices?

how can we answer these types of questions?

can anyone explain with simple example?


SCJP5 and SCWCD1.5
Think Twice Act Wise...
anand-k jha
Greenhorn

Joined: Dec 02, 2008
Posts: 15
Hi,

Please look below example:



Hashcode always will return a fixed value for an object, so
Second method is not appropriate here.
I think this will help you.

Anand.
Djonatah Stiegler
Ranch Hand

Joined: Oct 30, 2008
Posts: 32
I think you should choose the hashCode() method that uses the same variables used on the equals() method.

Bye
<><


From Brazil
 
GeeCON Prague 2014
 
subject: hashcode()...