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 Inquisition Mock - Doubt 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 "Inquisition Mock - Doubt" Watch "Inquisition Mock - Doubt" New topic
Author

Inquisition Mock - Doubt

Shivani Sharma
Greenhorn

Joined: Sep 22, 2009
Posts: 5
Hi Guys

In the following code :



Ans given is true.

Shouldn't it be false as hashcode is not overidden.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
No ... hashCode becomes important when working with collections to determine lookup locations for objects.

In collections, the hashCode determines the location to look for the object, then equals determines equality. Which also means two identical hashCode do not necessarily mean equality. The opposite however is true. Two equal objects must have the same hashCode.


JDBCSupport - An easy to use, light-weight JDBC framework -
Harsh Pensi
Ranch Hand

Joined: Aug 05, 2009
Posts: 67
Hi Shivani
I failed to understand why you need hashcode here
hashcode method has to be overridden if you want to be able to use the class properly in a collection that uses hashing.

SCJP6 - 93% SCWCD5 - 97%
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Shivani Sharma wrote:Hi Guys

In the following code :



Ans given is true.

Shouldn't it be false as hashcode is not overidden.


There is no underlying structure that tries to put these objects into "buckets". Try this



SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Shivani Sharma
Greenhorn

Joined: Sep 22, 2009
Posts: 5
Thanks a lot guys, got it.

 
GeeCON Prague 2014
 
subject: Inquisition Mock - Doubt