← Quiz: How Hashing Works: all 13 questions
Quiz: How Hashing Works · Question 6 of 13
A Java class overrides equals() but not hashCode(). What happens with a HashSet?
A Java class overrides equals() but not hashCode(). What happens with a HashSet?
- A.It works normally
- B.contains() can return false for an equal object, because it searches the wrong bucket
- C.It does not compile
- D.The set sorts the objects
Answer & explanation
Correct answer: contains() can return false for an equal object, because it searches the wrong bucket
Equal objects must have equal hash codes; the default hashCode is per object, so the bucket differs.
Can you get the rest right without peeking?
Take the timed Quiz: How Hashing Works quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →