This is a question from the ePractice exams for 310-055 purchased directly from Sun Microsystems.
Given:
Which two are true? (Choose two.)
A - Two instances of Sock with the same size and color will have the same hashcode.
B - Two instances of Sock with the same size and color might have different hashcodes.
C - A Hashtable that uses Sock instances as keys will always be able to successfully retrieve objects stored in it.
D - A Hashtable that uses Sock instances as keys will NOT always be able to successfully retrieve objects stored in it.
Sun's answer is:
Options B and D are correct. For Maps to work with Sock, hashCode must be properly overridden.
I disagree. According to
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html: If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
So shouldn't Option A be correct and not Option B? Please confirm.
Thank you!
Bonnie