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?
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?
To produce the desired output, the Person class needs to implement the Comparator<Person> interface for custom sorting. The compareTo method in option B is correctly written to compare the names of Person objects in reverse order, which is needed to produce the descending order output shown: 'John', 'Joe', and 'Jane'.
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.