@Override
public int compareTo(Student stu) { //实现compareTo方法
int num = new Integer(this.sum).compareTo(new Integer(stu.sum));
if(num == 0){
return this.name.compareTo(stu.name);
}
return num;
}
public int hashCode(){ //覆盖hashCode方法
return name.hashCode()+sum*66;
}
public boolean equals(Object obj){ //覆盖equals方法
if(!(obj instanceof Student))
throw new ClassCastException("类型不匹配");
Student stu = (Student)obj;
return this.name.equals(stu.name)&&this.sum==stu.sum;
}
public String toString(){ //重写toString方法
return "student["+name+","+mt+","+cn+","+en+"]";
}