1个回答
展开全部
public class Amimal implements Comparable<Amimal> {
private String name;
private int age;
@Override
public int compareTo(Amimal o) {
return o.getAge() - this.age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "[name="+this.name+",age="+this.age+"]";
}
}
private String name;
private int age;
@Override
public int compareTo(Amimal o) {
return o.getAge() - this.age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "[name="+this.name+",age="+this.age+"]";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询