Skip to content
Sharp

Core Java · interview question

Why does upcasting an object in terms of method accessibility change runtime behavior?

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

Correct answer

C. Only the methods defined in the reference type are accessible.

Why

When an object is upcasted, only the methods defined in the reference type (superclass or interface) are accessible. However, overridden methods in the subclass are invoked if called through these accessible methods.

Test yourself on Core Java

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

Start free test
All Core Java questions →