Skip to content
Sharp

Core Java · interview question

Why is it important to implement a consistent equals method in a class?

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

Correct answer

D. To ensure consistent behavior in collections.

Why

A consistent equals method is crucial for collections that depend on object equality, such as Set and Map, to function correctly. Without it, these collections can behave unpredictably.

Test yourself on Core Java

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

Start free test
All Core Java questions →