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!