Bird
0
0

What is the output of the following code?

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

    The Integer a is autounboxed to int to add 10.
  2. Step 2: Calculate the sum

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

    15 -> Option C
  4. Quick Check:

    Autounboxing + addition = 15 [OK]
Quick Trick: Wrapper auto-unboxes in arithmetic expressions [OK]
Common Mistakes:
  • Expecting compilation error due to wrapper usage
  • Confusing autoboxing with autounboxing
  • Thinking NullPointerException occurs without null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes