Java Quiz: 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.

कठिन 10 सवाल ~8 मिनट पास होने के लिए 80% Java 17

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

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

जवाब दिखाएं

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.

इस क्विज़ में क्या है

  • 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

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।