newton wrote:Apparently you may override hashCode() in this question, but you may not make o2 object point to o1.
Well, the problem statement explicitly says, "o1 and o2 denote two object references to two different objects of the same class." So you cannot make o1 and o2 point to the same object as that is not what the question is asking.
On the other hand, the problem statement does not make any claim about the class code. That is why you have to consider all the possibilities for the class code.
Can i expect these kinds of questions? And how will i know what i can and cannot do in a case like this one.
Yes, it is valid question. Most of the time it is quite straight forward. You need to work with what ever is given in the problem statement.
HTH,
Paul.