Car has a Driver — what type of OOP relationship is this?

Get ready for your Object‑Oriented Programming Test. Use flashcards and multiple-choice questions. Each question includes hints and explanations. Prepare for your exam today!

Multiple Choice

Car has a Driver — what type of OOP relationship is this?

Explanation:
This question tests how lifecycles and ownership define how objects relate. The Car having a Driver is a has-a relationship, but the Driver’s lifecycle isn’t tied to the Car’s. A Driver exists independently and can continue to exist even if a particular Car is removed, and the Driver could drive different cars over time. That weaker, lifecycle-independent connection is aggregation: the Car holds a reference to the Driver without owning its lifetime. In contrast, composition would imply the Driver’s lifecycle is bound to the Car—creating or destroying the Car would also create or destroy the Driver, which isn’t implied here. Inheritance would suggest Car is a kind of Driver, which isn’t accurate. A plain association describes a link between objects without emphasizing lifecycles, but aggregation is the more precise way to express a has-a relationship where both objects survive independently.

This question tests how lifecycles and ownership define how objects relate. The Car having a Driver is a has-a relationship, but the Driver’s lifecycle isn’t tied to the Car’s. A Driver exists independently and can continue to exist even if a particular Car is removed, and the Driver could drive different cars over time. That weaker, lifecycle-independent connection is aggregation: the Car holds a reference to the Driver without owning its lifetime.

In contrast, composition would imply the Driver’s lifecycle is bound to the Car—creating or destroying the Car would also create or destroy the Driver, which isn’t implied here. Inheritance would suggest Car is a kind of Driver, which isn’t accurate. A plain association describes a link between objects without emphasizing lifecycles, but aggregation is the more precise way to express a has-a relationship where both objects survive independently.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy