Skip to content
Sharp

Object-oriented programming · interview question

How can a subclass ensure that it maintains the contract of a superclass method while still providing additional functionality?

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

Correct answer

A. By calling super inside the overridden method and adding new code.

Why

A subclass can maintain the contract of the superclass method by calling the superclass's method using super and then adding its own functionality. This ensures that the original behavior is preserved while allowing the subclass to extend it.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →