Question: Q 3 4 . Give the Java SE program below: import java.util. * ; class Name { private String first , last; Name ( String

Q34. Give the Java SE program below:
import java.util.*;
class Name{
private String first , last;
Name(String f, String l){first f; last=l;}
Name(){}
@Override public String toString(){ return first ++last;}
Public static int compareByLastName(Name n1, Name n2)
{
return n1.last.compareTo(n2.last);
}
}
public class MethodRefTest{
public static void main(String[] args){
Name n1= new Name(Harry,Homeowner);
Name n2=new Name(Paul,Painter);
Name n3=new Name(Jane,Doe);
List nameList=Arrays.asList(n1,n2,n3);
******
Which of the following lines of code correctly sunstitute ****** to cause the program to compile and generate the output?
Jane Joe
Harry Homeowner
Paul Painter
a. nameList.sort(n1::compareByLastName);
nameList.forEach(System.out::println);
b. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out::println);
c. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out::println());
d. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out.println);
e. nameList.sort(Name::compareByLastName);
nameList.forEach(System.out.println());

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!