Oracle
1Z0-809 · Question #240
1Z0-809 Question #240: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #240. The question stem and answer options stay visible for context.
Question
Given the code fragments:
class Person // line n1
{
String name;
Person(String name) {
this.name = name;
}
} // line n2
and
List<Person> emps = new ArrayList<>();
// code that adds objects of the Person class to the emps list goes here */
Collections.sort(emps);
Which two modifications enable to sort the elements of the emps list? (Choose two.)
Options
- AReplace line n1 with class Person extends Comparator<Person>
- BAt line n2 insert public int compareTo (Person p) { return this.name.compareTo (p.name); }
- CReplace line n1 with class Person implements Comparable<Person>
- DAt line n2 insert public int compare (Person p1, Person p2) { return p1.name.compareTo (p2.name); }
- EAt line n2 insert public int compareTo (Person p, Person p2) { return p1.name.compareTo (p2.name); }
- FReplace line n1 with class Person implements Comparator<Person>
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.