Which two modifications enable to sort the elements of the emps list?

Given the code fragments:

and

Which two modifications enable to sort the elements of the emps list? (Choose two.)
A. Replace line n1 with class Person extends Comparator<Person>
B. At line n2 insert public int compareTo (Person p) { return this.name.compareTo (p.name);
}
C. Replace line n1 with class Person implements Comparable<Person>
D. At line n2 insert public int compare (Person p1, Person p2) { return p1.name.compareTo (p2.name);
}
E. At line n2 insert:
public int compareTo (Person p, Person p2) { return p1.name.compareTo (p2.name);
}
F. Replace line n1 with class Person implements Comparator<Person>

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “Which two modifications enable to sort the elements of the emps list?

  1. Option A is incorrect, because Comparator is interface, it should be implemented, not extended.

    Option C is correct, because only Comparable allowed here. And option B is correct, because Comparable interface decraler method compareTo with 1 argument.

    So correct answer is B, C.

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.