posted 15 years ago
Hi All,
I am really confused with ==, Equals and Hashcodes.
Can anyone please explain me the below question?
Q)Your program has two object references, x and y. In some method the following logical tests are done:
boolean hashFlag = ( x.hashCode() == y.hashCode() );
boolean equalsFlag = x.equals( y );
boolean eqFlag = ( x == y );
Which of the following statements about the relationship between these tests are true.
(1)If equalsFlag is true, then hashFlag must be true
(2)If hashFlag is true, then eqFlag must be true
(3)If equalsFlag is false, then eqFlag must be false
(4)if hashFlag is false, then eqFlag must be false
Ans:1,3 and 4.
Thanks,
Jaimesh.