LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Inheritance and Polymorphism MCQ · Question 15

Inheritance or composition? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

A Car needs an Engine. Which design is usually better?

  • A Inheritance: class Car(Engine)
  • B Multiple inheritance: class Car(Engine, Wheel)
  • C Composition: give Car an engine attribute (a car has an engine) Correct
  • D Make Engine an abstract class of Car
Correct Answer: Option C

Inheritance models "is a"; a car is not an engine.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links