Share on Google+Share on Google+

SCJP Module-9 Question-20

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>();
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





Posted on: July 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.