What is the result?

Given:

public static Collection get() {
Collection sorted = new LinkedList();
sorted.add(“B”); sorted.add(“C”); sorted.add(“A”);
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + “, “);
}
}

What is the result?

Given:

public static Collection get() {
Collection sorted = new LinkedList();
sorted.add(“B”); sorted.add(“C”); sorted.add(“A”);
return sorted;
}
public static void main(String[] args) {
for (Object obj: get()) {
System.out.print(obj + “, “);
}
}

What is the result?

A.
A, B, C,

B.
B, C, A,

C.
Compilation fails.

D.
The code runs with no output.

E.
An exception is thrown at runtime.



Leave a Reply 1

Your email address will not be published. Required fields are marked *