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.
Compilation fails.

B.
B, C, A,

C.
An exception is thrown at runtime.

D.
The code runs with no output.

E.
A, B, C,



Leave a Reply 0

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