Skip to content
Sharp

Core Java · interview question

Which of the following scenarios could lead to a NullPointerException when using Integer objects?

Multiple choiceHardchapter-7-curatedpremiumcore-javawrapper-types-and-autoboxing
java
Integer num = null;
int value = num;
Choose one answer
Answer and explanation

Correct answer

C. Unboxing a null Integer to an int

Why

Unboxing a null Integer reference to a primitive int leads to a NullPointerException because it attempts to dereference a null object.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →