Problem Statement
Give one scenario where composition is preferable to inheritance and explain why.
Explanation
Prefer composition to avoid tight coupling and fragile base class—e.g., reuse behavior by delegating to a helper instead of extending.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Java · Interview Question
Detailed answer, explanation and code for this interview question. Ideal for Java interview preparation, coding rounds and viva questions.
Give one scenario where composition is preferable to inheritance and explain why.
Master Java with our complete collection of questions, tutorials and guides.