Skip to content
Sharp

Core Java · interview question

How would you explain the hidden danger in Integer quantity = null; int count = quantity; in an interview?

Multiple choiceEasychapter-7-curatedpremiumcore-javawrapper-types-and-autoboxing
Choose one answer
Answer and explanation

Correct answer

B. Autounboxing will throw a NullPointerException at runtime.

Why

Java will try to unbox the Integer into a primitive int. If the wrapper is null, that conversion fails at runtime, which is why wrappers should be used intentionally rather than by accident.

Test yourself on Core Java

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

Start free test
All Core Java questions →