Multiple choice technology architecture

Example of Decorator pattern in Java API?

  1. java.util.List

  2. java.lang.String

  3. java.io.BufferedInputStream.

  4. None of the above.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

java.io.BufferedInputStream wraps another InputStream (like FileInputStream) to add buffering functionality. Both implement the InputStream interface, and BufferedInputStream adds behavior (buffering for performance) without changing the underlying stream - this is the Decorator pattern in action. java.util.List and java.lang.String are not examples of Decorator.