🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.It works normally
  2. B.contains() can return false for an equal object, because it searches the wrong bucket
  3. C.It does not compile
  4. 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 →