class Student implements Comparable<Student>
{
private String name;
private int ma,cn,en;
private int sum;
Student(String name,int ma,int cn,int en)
{
this.name=name;
this.ma=ma;
this.cn=cn;
this.en=en;
sum=ma+cn+en;
}
public int compareTo(Student s)
{
int num=new Integer(this.sum).compareTo(new Integer(s.sum));
if(num==0)
return this.name.compareTo(s.name );
return num;
}
这段代码class Student implements Comparable<Student>与这个public int compareTo(Student s)都是成对出现的吗?
请解释一下这两句代码,谢啦!
|