Could you tell me the source of this question? Also please use "Code" tags so that your code is more readable to others!
The rule is:
If hashCode() is same, equals() may be true, may not be true
If equals() is true, hasCode() needs to be same.
I don't understand why...
If o1 has code="a", b=2, c=3 and
o2 has code="a", b=3, c=2 then
o1.equals(o2) == true, but o1.hashCode() != o2.hashCode !!!
I do agree with your statement. In this case even though objects being equal is "true", hashCodes be equal is "false". This seems to violate the equals hashCode contract. May be I am overlooking something?
Joined: May 11, 2010
I attach oryginal question with answer. Maybe I rewrite something wrong?
But all time I don't think why D is correct - I hope, that I have'nt this question on exam.
Thanks for reply.