The Sample program given below will check your knowledge about the Collection Interface of the and object initialization.
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
(2)