Skip to content
Sharp

Object-oriented programming · interview question

In the context of the 'Open/Closed Principle', how does composition support this principle?

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

Correct answer

B. By allowing classes to be open for extension but closed for modification.

Why

Composition supports the Open/Closed Principle by allowing new functionality to be added through composition without modifying existing code, making systems easier to maintain and extend.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →