~/ learn/ comp-308/ cards/ Composition vs inheritance; extends & super
1 of 5

Composition: Car holds an Engine and delegates

Composition: Car holds an Engine and delegates

Answer

class Car { private final Engine engine = new Engine(); void drive() { engine.start(); } }

`Car` has-an `Engine`. It owns the reference and forwards `drive()` to the engine's `start()` — delegation, not inheritance.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF