Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
Java - Wrapper Classes
What is the output of the following code?
Integer a = 10;
int b = a + 5;
System.out.println(b);
A10
B15
CCompilation error
DNullPointerException
Step-by-Step Solution
Solution:
  1. Step 1: Analyze autoboxing and unboxing

    Variable a is an Integer object holding 10. When used in arithmetic, it is unboxed to int.
  2. Step 2: Calculate expression

    Unboxed a (10) plus 5 equals 15, which is stored in b and printed.
  3. Final Answer:

    15 -> Option B
  4. Quick Check:

    Unboxing converts wrapper to primitive for arithmetic [OK]
Quick Trick: Wrapper unboxes automatically in arithmetic expressions [OK]
Common Mistakes:
  • Expecting object reference printed instead of value
  • Thinking autoboxing causes errors in arithmetic
  • Ignoring unboxing in expressions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes