🎙 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 6 of 10

Why must a decorator implement the same interface as the object it wraps?

Why must a decorator implement the same interface as the object it wraps?

  1. A.Java does not allow wrapping otherwise
  2. B.So the wrapped result can be used anywhere the original is used and wrapped again
  3. C.To make it faster
  4. D.So that it can be a Singleton
Answer & explanation

Correct answer: So the wrapped result can be used anywhere the original is used and wrapped again

Same interface means decorators can be stacked in any order.

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 →