Skip to content
Sharp

Object-oriented programming · interview question

Why should you prefer composition over inheritance when designing a Product and Cart relationship?

Multiple choiceMediumchapter-2-curatedpremiumoopobject-references
Choose one answer
Answer and explanation

Correct answer

C. Composition allows for more flexible and modular design.

Why

Composition allows for a more flexible design because it enables objects to be composed of other objects, promoting code reuse and reducing dependency.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →