nerdexam
Oracle

1Z0-819 · Question #70

1Z0-819 Question #70: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #70. The question stem and answer options stay visible for context.

Question

public class Tester { public static class Person implements /* line 1 / { private String name; Person(String name) { this.name = name; } / line 2 */ } public static void main(String[] args) { Person[] people = new Person("Mary"), new Person("Jane"); new Person("John"); Arrays.sort(people); for (Person person: people) System.out.println(person.name); } } You want the code to produce this output: Jane John Mary Which code fragment should be inserted on line 1 and line 2 to produce the output?

Options

  • AInsert Comparator<Person> on line 1. Insert public int compare(Person p1, Person p2) { return p1.name.compare(p2.name); } on line 2.
  • BInsert Comparator<Person> on line 1. Insert public int compareTo(Person person) { return person.name.compare(this.name); } on line 2.
  • CInsert Comparable<Person> on line 1. Insert public int compare(Person p1, Person p2) { return p1.name.compare(p2.name); } on line 2.
  • DInsert Comparator<Person> on line 1. Insert public int compare(Person person) { return person.name.compare(this.name); } on line 2.

Unlock 1Z0-819 to see the answer

You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 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.

Full 1Z0-819 Practice