Skip to content
Sharp

Core Java · interview question

Why is it useful to upcasting in Java?

Multiple choiceEasychapter-5-curatedpremiumcore-javaupcasting-and-dynamic-dispatch
Choose one answer
Answer and explanation

Correct answer

D. To allow a subclass reference to be treated as a superclass reference.

Why

Upcasting allows a subclass reference to be treated as a superclass reference, providing flexibility and enabling polymorphism. This allows you to write more general code by referring to objects through their superclass type.

Test yourself on Core Java

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

Start free test
All Core Java questions →