Skip to content
Sharp

Core Java · interview question

Why is left == right risky when left and right are Integer objects?

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

Correct answer

B. Because == compares wrapper references, not reliable value equality

Why

With wrapper objects, == checks whether both references point to the same object, not whether the numeric values are equal. Prefer value comparison such as equals() when you mean numeric equality.

Test yourself on Core Java

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

Start free test
All Core Java questions →