Skip to content
Sharp

Core Java · interview question

Which statement is true regarding the relationship between hashCode and equals?

Multiple choiceMediumchapter-4-curatedpremiumcore-javaequals-and-hashcode-in-collections
Choose one answer
Answer and explanation

Correct answer

A. Equal objects must have the same hashCode.

Why

The general contract is that if two objects are equal according to the equals method, they must return the same hashCode. This ensures correct operation in hash-based collections.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →