🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Observer, Strategy and Decorator: all 10 questions

Quiz: Observer, Strategy and Decorator · Question 10 of 10

Decorator differs from inheritance because a decorator:

Decorator differs from inheritance because a decorator:

  1. A.Changes every object of the class at compile time
  2. B.Cannot call the wrapped object's methods
  3. C.Requires multiple inheritance
  4. D.Adds behaviour to one object at runtime, and decorators can be combined freely
Answer & explanation

Correct answer: Adds behaviour to one object at runtime, and decorators can be combined freely

Inheritance fixes behaviour per class at compile time; decorators are stacked per object.

Can you get the rest right without peeking?

Take the timed Quiz: Observer, Strategy and Decorator quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →