~/ 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/0a5466aa-0ea7-4554-abc8-2a224f53cbfb/flashcard utf-8 LF