nerdexam
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)
  • A
    6% (1)
  • B
    83% (15)
  • C
    6% (1)
  • E
    6% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice