Home Tutorial Java Scjp Part9 SCJP Module-9 Question-10

 
 

Share on Google+Share on Google+
SCJP Module-9 Question-10
Posted on: July 16, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-9 Question-10:


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.

Posted on: July 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com