Question: Given Queue<? super OutputStream> queue = new ArrayBlockingQueue<OutputStream>(10), what are the following code compiles?
Choice:
A. queue.add(new OutputStream());
B. queue.add(new FileOutputStream());
C. queue.add(new FileWriter());
D. queue.add(new BufferedOutputStream());
E. queue.add(new ObjectOutputStream());
F. queue.add(new BufferedWriter());
G. queue.add(new FilterInputStream());
H. queue.add(new PrintStream());
Explain: regardless of the right side assignment, only the left side type declaration counts: Queue<? super OutputStream> queue. You can only add the subclass of OutputStream to the queue. Of course you need to be familiar with NIO classes. We didn't choose A because OutputStream is an abstract class.