What is the result?

Given:

11. public static Collection get() {
12. Collection sorted = new LinkedList();
13. sorted.add(“B”); sorted.add(“C”); sorted.add(“A”);
14. return sorted;
15. }
16. public static void main(String[] args) {
17. for (Object obj: get()) {
18. System.out.print(obj + “, “);
19. }
20. }

What is the result?

Given:

11. public static Collection get() {
12. Collection sorted = new LinkedList();
13. sorted.add(“B”); sorted.add(“C”); sorted.add(“A”);
14. return sorted;
15. }
16. public static void main(String[] args) {
17. for (Object obj: get()) {
18. System.out.print(obj + “, “);
19. }
20. }

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 0

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