Bird
0
0

What is the output of this Java code?

medium📝 Predict Output Q13 of 15
Java - Wrapper Classes
What is the output of this Java code?
Integer a = 5;
int b = a + 10;
System.out.println(b);
ANullPointerException
B510
CCompilation error
D15
Step-by-Step Solution
Solution:
  1. Step 1: Understand unboxing in expression

    Variable 'a' is Integer object; adding 10 triggers unboxing 'a' to int 5.
  2. Step 2: Calculate the sum and print

    5 + 10 = 15, so output is 15 printed.
  3. Final Answer:

    15 -> Option D
  4. Quick Check:

    Unboxing Integer 5 + 10 = 15 [OK]
Quick Trick: Unboxing happens automatically in arithmetic expressions [OK]
Common Mistakes:
  • Thinking it concatenates as string '510'
  • Expecting compilation error due to wrapper usage
  • Confusing with NullPointerException if variable was null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes