Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 144

Given the code fragments:

and

Which two modifications enable to sort the elements of the emps list? (Choose two.)

    Correct Answer: B, C

    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.

Discussion
Manuel7000

Agree and tested

DarGrinOptions: BC

Anser is B and C, since class Person should implement Comparable Interface and implement its method : int compareTo(T o)

steefaandOptions: BC

B and C are true.

samtash1034Options: BC

b,c,tested