Skip to content
Sharp

Object-oriented programming · interview question

What can cause a ClassCastException in a polymorphic Java application?

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

Correct answer

A. Attempting to cast an object to a subclass that it is not an instance of

Why

A ClassCastException occurs when you try to cast an object to a subclass that it is not an instance of. This is a common pitfall in polymorphic applications where runtime type checking can fail if casting is not done carefully.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →