Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q14 of 15
Java - Wrapper Classes
Identify the error in the following code snippet:
Integer x = null;
int y = x + 5;
System.out.println(y);
ACompilation error due to null assignment
BOutput is 0
COutput is 5
DNullPointerException at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Analyze autounboxing with null wrapper

    Variable x is null, so autounboxing to int causes error.
  2. Step 2: Identify runtime exception

    Autounboxing null throws NullPointerException at runtime.
  3. Final Answer:

    NullPointerException at runtime -> Option D
  4. Quick Check:

    Autounboxing null causes NullPointerException [OK]
Quick Trick: Autounboxing null causes NullPointerException [OK]
Common Mistakes:
  • Expecting compilation error instead of runtime error
  • Assuming null converts to zero
  • Ignoring autounboxing behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes