exam questions

Exam 1z0-816 All Questions

View all questions & answers for the 1z0-816 exam

Exam 1z0-816 topic 1 question 36 discussion

Actual exam question from Oracle's 1z0-816
Question #: 36
Topic #: 1
[All 1z0-816 Questions]

Given:

You want the code to produce this output:

John -

Joe -

Jane -
Which code fragment should be inserted on line 1 and line 2 to produce the output?

  • A. Insert Comparator<Person> on line 1.

    Insert -
    public int compare(Person p1, Person p2) {
    return p1.name.compare(p2.name);
    }
    on line 2.
  • B. Insert Comparator<Person> on line 1.

    Insert -
    public int compareTo(Person person) {
    return person.name.compareTo(this.name);
    }
    on line 2.
  • C. Insert Comparable<Person> on line 1.

    Insert -
    public int compare(Person p1, Person p2) {
    return p1.name.compare(p2.name);
    }
    on line 2.
  • D. Insert Comparator<Person> on line 1.

    Insert -
    public int compare(Person person) {
    return person.name.compare(this.name);
    }
    on line 2.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Sa16253748596
5 months, 2 weeks ago
Selected Answer: B
A,B,C,D are all wrong. B is better than the others. Insert Comparator<Person> on line 1. Correct. Insert - public int compare(Person person) { return person.name.compareTo(this.name); } on line 2. is correct.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago