日期:2014-05-20  浏览次数:20693 次

新人请教,最简单接口问题;不懂。高手讲解下,程序有点小错误
class Employee implements Comparable{
String name;
int age ;
public Employee(String n, int a){
name =n;
age=a;
}
public int compareTo(Object obj){
Employee emp=(Employee)obj;
if(age<emp.age)
return -1;
else if(age>emp.age)
return 1;
else return 0;
}
public String getName{
reture Nem;
}
public int getAge(){
retrn age;
}
}
public class SortTest{
public static void main(String[] args){
Employyee[] emp={new Employee("Harry",23),
new Employee("Carl",27),
new Employee("Tony",21)};
Arrays.sort(emp);
for(int i=0;i<emp.length;i++){
System.out.print("name="+emp[i].getName()+",age="+emp[i].getAge());
}}}

------解决方案--------------------
你那里不懂?