Java Quiz: String Pool & Immutability

This Java quiz tests one of the most asked interview topics, the string pool and string immutability. You will predict what == and equals() print for literals, new String(), intern() and compile-time constants, and spot the code that throws.

मीडियम 10 सवाल ~6 मिनट पास होने के लिए 80% Java 17

मोड चुनें

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

सैंपल सवाल

सवाल 1 / 10

What does this print?

public class Main {
    public static void main(String[] args) {
        String a = "hi";
        String b = "hi";
        System.out.println(a == b);
    }
}
जवाब दिखाएं

B. true Identical string literals are stored once in the string pool, so a and b point to the same object and == is true. That is an implementation detail of literals, not a reason to compare strings with ==.

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

  • == (same object) vs equals() (same text)
  • String literals and the string pool
  • new String() and intern()
  • Compile-time constant concatenation and final
  • Why String methods return new strings

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

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

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

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

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