未覆盖compareTo抽象方法是什么样的错误??
错误提示是 Name不是抽象的,并且未覆盖java.中的抽象方法compareTo<java.lang.Object>Class Name implements Comparable
^
程序代码:
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=(o.lastName); return(lastCmp!=0?lastCmp:(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()); } }