Skip to content
Sharp

Object-oriented programming · interview question

How would you explain a drawback of using inheritance over composition when implementing a 'NotificationService' that supports multiple channels like email, SMS, and push notifications in an interview?

Multiple choiceHardchapter-5-curatedpremiumoopcomposition-vs-inheritance
Choose one answer
Answer and explanation

Correct answer

D. Inheritance limits the ability to extend functionality without modifying existing code.

Why

Using inheritance may limit the ability to extend functionality because changes in the superclass can affect all subclasses. Composition allows new channels to be added without modifying existing code, thus adhering to the open/closed principle.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →