Question
In Java, which comparison about Inheritance vs Composition is accurate?
- There is no practical difference in behavior, performance, or API design when Inheritance vs Composition is involved.
- Inheritance models an is-a relationship, while composition models collaborating parts or a has-a relationship.
- The oldest option related to Inheritance vs Composition is always the right production choice regardless of context.
- Differences around Inheritance vs Composition are mostly cosmetic, so correctness and maintainability do not change.
Hint
Focus on the behavior or tradeoff, not just the keyword.
Answer and rationale
Correct answer: B. Inheritance models an is-a relationship, while composition models collaborating parts or a has-a relationship.
Inheritance models an is-a relationship, while composition models collaborating parts or a has-a relationship. This is the comparison that usually separates memorization from understanding.
Track: Java