Another cup of my favourite answers! This is question #53 from the first exam in K&B's CD.
The question presents a series of conditions over some object instances of unknow type, named x1, x2, x3, x4, x5 and x6. I'll skip the irrelevant stuff and post an equivalent question:
Given:
...
x5.equals(x6) == true
...
Which of the following statements will always be true? (Choose all that apply):
...
x5.hashCode() == x6.hashCode()
...
That answer was considered the correct and the others were all incorrect. But either the question is formulated wrongly or the answer is not correct.
We can clearly have a class where two equal objects have different hashCodes:
So the question should have rather been: "Which, according to the hashCode contract, should be always true?".Some questions are extremely picky on its language and others are leaving so much up to supposition. Not fair!