Please explain what is the contract between equals and hashCode of an object?

Submitted by: Muhammad
The only obligation is that for any objects o1 and o2 then if o1.equals(o2) is true then o1.hashCode() == o2.hashCode() is true.

Note that this relationship goes only one way: for any o1, o2 of some class C, where none of o1 and o2 are null, then it can happen that o1.hashCode() == o2.hashCode() is true BUT o1.equals(o2) is false.
Submitted by: Muhammad

Read Online Full Stack Developer (Java) Job Interview Questions And Answers