Skip to content
Sharp

Core Java · interview question

What will be the result of adding the same object twice to a HashSet?

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

Correct answer

D. The object will only appear once in the HashSet.

Why

A HashSet does not allow duplicate entries. If an attempt is made to add the same object twice, it will not be added again, ensuring that each object appears only once in the set.

Test yourself on Core Java

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

Start free test
All Core Java questions →