Share on Google+Share on Google+

SCJP Module-9 Question-10

The given program will test your knowledge of Queue Interface and LinkedList class of the collection framework.

Given below the sample code :

import java.util.LinkedList;
import java.util.Queue;
public class Check {
public static void main(String... args) {
Queue<String> que = new LinkedList<String>();
public static void show(Queue q) {
que.add(new Integer(12));
while (!que.isEmpty ( ) )
System.out.print(que.poll() + " ");

What will be the output of the above code ?

1. Compile error

2. Delhi  Mumbai  Dhaka  12

3.  Delhi  Mumbai  Dhaka

4.  Delhi  Mumbai 




The 'que' was declared as Queue<String> originally . But it is passed as an untyped Queue in show() method ,after that it is legal to add ineger.


Posted on: July 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.