Bird
0
0

Find the error in this code:

medium📝 Debug Q7 of 15
Java - Wrapper Classes
Find the error in this code:
int a = 5;
Integer b = null;
int c = a + b;
Ac equals 0
BCompilation error: cannot add int and Integer
Cc equals 5
DNullPointerException at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Analyze addition with null Integer

    Variable b is null, unboxing b causes NullPointerException.
  2. Step 2: Confirm runtime behavior

    Code compiles but throws exception when adding int and null Integer.
  3. Final Answer:

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

    Unboxing null in arithmetic throws exception [OK]
Quick Trick: Adding null wrapper to int causes NullPointerException [OK]
Common Mistakes:
  • Expecting compilation error
  • Assuming null treated as zero
  • Ignoring runtime exceptions from unboxing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes