Skip to content
Sharp

Core Java · interview question

In an inheritance hierarchy, what is a reason to choose composition over inheritance?

Multiple choiceMediumchapter-5-curatedpremiumcore-javacode-reading-with-related-types
Choose one answer
Answer and explanation

Correct answer

D. To avoid a rigid class structure.

Why

Composition is often chosen over inheritance to avoid a rigid class structure and to increase flexibility and maintainability by reducing the dependency between classes.

Test yourself on Core Java

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

Start free test
All Core Java questions →