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
(2)
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.