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

 
 

SCJP Module-9 Question-20
Posted on: July 17, 2010 at 12:00 AM
The Sample program given below will check your knowledge about the Collection Interface of the and object initialization.

Given below the sample code :

import java.util.*;
public class Mycol {
public static Collection<String> fetch() {
Collection<String> col = new LinkedList<String>();
col.add("B");
col.add("C");
col.add("A");
return col;
}
public static void main(String[] args) {
for (Object myobj : fetch()) {
System.out.print(myobj + ", ");
}
}
}

What will be the output of the above code?

1. Compilation error.

2. B C A

3. A C B

4. No output

Answer

(2)

 

Related Tags for SCJP Module-9 Question-20: