Given the code fragments:
andWhich two modifications enable to sort the elements of the emps list? (Choose two.)
Given the code fragments:
andWhich two modifications enable to sort the elements of the emps list? (Choose two.)
To enable sorting of the elements in the emps list, the Person class must implement the Comparable interface and provide an implementation for the compareTo method. Replacing line n1 with 'class Person implements Comparable<Person>' (Option C) makes the Person class implement Comparable, which provides the compareTo method that Collections.sort requires. Inserting the method 'public int compareTo(Person p) { return this.name.compareTo(p.name); }' at line n2 (Option B) provides the necessary logic for comparing Person objects based on their names. With these modifications, the Collections.sort(emps) call will work correctly, because the Person objects will know how to compare themselves.
Agree and tested
Anser is B and C, since class Person should implement Comparable Interface and implement its method : int compareTo(T o)
B and C are true.
b,c,tested