nerdexam
Oracle

1Z0-819 · Question #54

Which code fragment compiles?

The correct answer is D. D. Comparator<Integer> comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } }. See the full explanation below for the reasoning.

Question

Which code fragment compiles?

Options

  • AA. Comparator comparator = new Comparator<?>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
  • BB. var comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
  • CC. Comparator<> comparator = new Comparator<Integer>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };
  • DD. Comparator<Integer> comparator = new Comparator<>() { public int compare(Integer i, Integer j) { return i.compareTo(j); } };

How the community answered

(46 responses)
  • A
    9% (4)
  • B
    17% (8)
  • C
    4% (2)
  • D
    70% (32)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice