What two statements are true about properly overridden hashCode() and equals()
methods?
A. hashCode() doesn’t have to be overridden if equals() is.
B. equals() doesn’t have to be overridden if hashCode() is.
C. hashCode() can always return the same value, regardless of the object that invoked it.
D. If two different objects that are not meaningfully equivalent both invoke hashCode(),
then hashCode() can’t return the same value for both invocations.
E. equals() can be true even if it’s comparing different objects.
Answers given are C, E.
My question is regarding option E.
Once the equals and hashCode are properly overrriden[This is mentioned in the question], how come two different objects can return true when equls() is called? Can any one give me an example?
methods?
A. hashCode() doesn’t have to be overridden if equals() is.
B. equals() doesn’t have to be overridden if hashCode() is.
C. hashCode() can always return the same value, regardless of the object that invoked it.
D. If two different objects that are not meaningfully equivalent both invoke hashCode(),
then hashCode() can’t return the same value for both invocations.
E. equals() can be true even if it’s comparing different objects.
Answers given are C, E.
My question is regarding option E.
Once the equals and hashCode are properly overrriden[This is mentioned in the question], how come two different objects can return true when equls() is called? Can any one give me an example?