Which statements are true about comparing two instances of the same class,
given that the equals()
and hashCode()
methods have been properly overridden?
Choose all that apply.
equals()
method returns true, the hashCode()
comparison == might return falseequals()
method returns false, the hashCode()
comparison == might return truehashCode()
comparison == returns true, the equals()
method must return truehashCode()
comparison == returns true, the equals()
method might return truehashCode()
comparison != returns true, the equals()
method might return trueB and D.
B is true because often two dissimilar objects can return the same hash code value.
D is true because if the hashCode()
comparison returns ==, the two objects might or might not be equal.
A, C, and E are incorrect.
C is incorrect because the hashCode()
method is very flexible in its return values, and often two dissimilar objects can return the same hash code value.
A and E are a negation of the hashCode()
and equals()
contract.