If two Java objects are equal according to equals, what must be true of their hashCode values?
Correct answer C. They must be the same
Explanation
The Object contract requires equal objects to return equal hash codes, otherwise hash-based collections look in the wrong bucket and fail to find them. The reverse is not required, as unequal objects may share a hash code. This is why a class that overrides equals should always override hashCode too.
Answer checked How we write and check questions
Discussion