Quiz de Java: equals() & hashCode()

This Java quiz goes deep into equals() and hashCode(), a favorite interview topic. You will predict how objects behave in a HashSet, catch an equals that overloads instead of overrides, and meet the Integer cache and records.

Difícil 10 perguntas ~8 minutos Aprovação com 80% Java 17

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 10

Which hashCode() for a class with int fields x and y follows the contract but makes a HashMap with many keys very slow?

Mostrar a resposta

C. return 42; A constant hash is legal, since equal objects still get equal hash codes, but every key lands in the same bucket and lookups degrade to scanning. Good hash codes spread different objects out.

O que este quiz cobre

  • Reference equality vs equals()
  • The equals/hashCode contract
  • Why HashSet and HashMap need both methods
  • Mutable keys and overloaded equals
  • The Integer cache and records

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.