Bird
0
0

What is the output of this Java code?

medium📝 Predict Output Q4 of 15
Java - Wrapper Classes
What is the output of this Java code?
Integer a = 7;
int b = a + 3;
System.out.println(b);
A73
B10
C7
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Identify unboxing in expression

    Variable 'a' is Integer, 'b' is int. 'a + 3' unboxes 'a' to int and adds 3.
  2. Step 2: Calculate the result

    7 + 3 = 10, so b = 10, printed output is 10.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    Unboxing allows arithmetic with wrapper objects [OK]
Quick Trick: Unboxing allows Integer in arithmetic expressions [OK]
Common Mistakes:
  • Thinking output is string concatenation
  • Expecting compilation error due to type mismatch
  • Confusing wrapper object with string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes