Thanks,
Sudhanshu(OCPJP,OCEJPAD)
marlajee Borstone wrote:This code segment will display objects are equal even though firstBook and secondBook reference two distinct objects. They are considered equal because the objects compared contain the same value.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Santosh Kumar Nayak wrote:In that scenario when we are using the hashcode method of the Object class then what is the int value returned from the Hashcode method ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Santosh Kumar Nayak wrote:In that scenario when we are using the hashcode method of the Object class then what is the int value returned from the Hashcode method ?
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects.
Joanne
Santosh Kumar Nayak wrote:Then in that scenario the complexity for retrieving value will be less as compared to complexity for retrieving value if the hashcode was same for all the objects ?
Joanne
Rico Felix wrote:You need to override both the equals(Object) and hashCode() methods only when you need to store those objects in data structures that uses hashing algorithms for storing data (key-value pairs).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|