import java.util.*;
class Name implements Comparable
{ public String firstName,lastName;
public Name(String firstName,String lastName)
{ this.firstName=firstName;
this.lastName=lastName;
}
public int compareTo(Name o)
{ int lastCmp=lastName.compareTo(o.lastName);
return(lastCmp!=0?lastCmp:firstName.compareTo(o.firstName));
}
public String toString()
{ return firstName+" "+lastName;
}
}
public class NameSort
{ public static void main(String args[])
{ Name nameArray[]=
{ new Name("John","Lennon"),
new Name("Karl","Marx"),
new Name("Groucho","Marx"),
new Name("Oscar","Grouch")};
Arrays.sort(nameArray);
for(int i=0;i<nameArray.length;i++)
System.out.println(nameArray[i].toString());
}
}