🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: HashMap and Maps: all 10 questions

Quiz: HashMap and Maps · Question 3 of 10

If you override equals() in a key class, what else must you override?

If you override equals() in a key class, what else must you override?

  1. A.toString()
  2. B.hashCode()
  3. C.compareTo()
  4. D.finalize()
Answer & explanation

Correct answer: hashCode()

Equal objects must have equal hash codes, or HashMap and HashSet won't find them.

Can you get the rest right without peeking?

Take the timed Quiz: HashMap and Maps quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →