Java OCA OCP Practice Question 1639

Question

Which of the following declares a Comparator where all objects are treated as equal?

  • A. Comparator<Character> comp = (c1)-> 0;
  • B. Comparator<Character> comp = (c1)-> {0};
  • C. Comparator<Character> comp = (c1, c2)-> 0;
  • D. Comparator<Character> comp = (c1, c2)-> {0};


C.

Note

A Comparator takes two parameters, so Options A and B are incorrect.

Option D doesn't compile.

When using brackets, a return keyword and semicolon are required.

Option C is a correct implementation.




PreviousNext

Related