🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Observer, Strategy and Decorator: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. In the Observer pattern, what does the subject know about its observers?
  2. Q2. What does this print? (code)
  3. Q3. Collections.sort(list, comparator) is an example of which pattern?
  4. Q4. A canteen bill uses if (type == STUDENT) … else if (type == STAFF) …. Which pattern removes this chain?
  5. Q5. What does this print? (code)
  6. Q6. Why must a decorator implement the same interface as the object it wraps?
  7. Q7. With 3 optional coffee add-ons, how many subclasses would you need to cover every combination (including plain coffee) without Decorator?
  8. Q8. Which JDK class is a well-known Decorator?
  9. Q9. What is a common bug when using the Observer pattern in long-running apps?
  10. Q10. Decorator differs from inheritance because a decorator: