Skip to content
Sharp

Object-oriented programming · interview question

Which of the following scenarios can lead to a compile-time error when overriding a method?

Multiple choiceHardchapter-5-curatedpremiumoopmethod-overriding
Choose one answer
Answer and explanation

Correct answer

C. Changing the return type to a non-subtype.

Why

A compile-time error will occur if the return type of the overriding method is not a subtype of the original method's return type. Method names and signatures must match exactly, and the @Override annotation does not cause errors if used correctly.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →