🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Wrapper Classes and Autoboxing: all 10 questions

Quiz: Wrapper Classes and Autoboxing · Question 4 of 10

Which line can throw a NullPointerException even though it calls no method?

Which line can throw a NullPointerException even though it calls no method?

  1. A.Integer x = null;
  2. B.int x = map.get("key"); where map is a Map<String, Integer>
  3. C.Integer x = map.get("key");
  4. D.String s = null;
Answer & explanation

Correct answer: int x = map.get("key"); where map is a Map<String, Integer>

If the key is missing, get returns null and unboxing it to int calls intValue() on null.

Can you get the rest right without peeking?

Take the timed Quiz: Wrapper Classes and Autoboxing quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →