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

 
 

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

 

Advertisement

Related Tags for SCJP Module-9 Question-20:


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 17, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com