Prepare for the Object-Oriented Programming Test with flashcards and multiple choice questions. Each question comes with hints and explanations to enhance understanding. Master OOP concepts and succeed in your exam!

Multiple Choice

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

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.