Skip to content
Sharp

Object-oriented programming · interview question

What happens when you cast a superclass reference to a subclass type in Java?

Multiple choiceMediumchapter-5-curatedpremiumooppolymorphism
Choose one answer
Answer and explanation

Correct answer

A. Successful if the object was instantiated as the subclass

Why

Casting a superclass reference to a subclass type is successful only if the object was originally instantiated as an instance of that subclass. Otherwise, it results in a ClassCastException at runtime.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →