Skip to content
Sharp

Core Java · interview question

How would you explain a common mistake when implementing equals and hashCode that can lead to incorrect Set behavior in an interview?

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

Correct answer

C. Using mutable fields in equals and hashCode.

Why

Using mutable fields in equals and hashCode can lead to incorrect behavior if the fields change after the object is added to a Set. This can result in inconsistent behavior and duplicate entries.

Test yourself on Core Java

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

Start free test
All Core Java questions →