Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Java - Wrapper Classes
What will be the output of this code?
Integer a = 1000; Integer b = 1000; System.out.println(a == b);
Afalse
BRuntime exception
CCompilation error
Dtrue
Step-by-Step Solution
Solution:
  1. Step 1: Understand '==' with wrapper objects

    Using '==' compares object references, not values, for wrapper objects.
  2. Step 2: Integer caching range

    Integer caches values from -128 to 127. 1000 is outside this range, so a and b refer to different objects.
  3. Final Answer:

    false -> Option A
  4. Quick Check:

    '==' compares references, 1000 not cached = false [OK]
Quick Trick: Use equals() to compare wrapper values, not '==' [OK]
Common Mistakes:
  • Assuming '==' compares values for wrappers
  • Ignoring Integer cache range
  • Expecting compilation or runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes