SCJP Module-9 Question-10


 

SCJP Module-9 Question-10

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

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>();
que.add("Delhi");
que.add("Mumbai");
que.add("Dhaka");
show(que);
}
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 

Answer

(2)

Explanation

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.

Ads