Oracle
1Z0-851 · Question #269
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…
The correct answer is B. B, C, A. See the full explanation below for the reasoning.
Question
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?
Options
- AA, B, C,
- BB, C, A,
- CCompilation fails.
- DThe code runs with no output.
- EAn exception is thrown at runtime.
How the community answered
(18 responses)- A6% (1)
- B83% (15)
- C6% (1)
- E6% (1)
Community Discussion
No community discussion yet for this question.