compareTo方法的实现

2017-11-11  本文已影响0人  地表最强程序员小白
public class test1 {
    public static void main(String[] args){
        student a=new student(56);
        student b=new student(99);
        System.out.println(a.compareTo(b));
    }
}
class student implements Comparable{
    double marks;
    student(double m){
        this.marks=m;
    }
    public int compareTo(Object o){
        student p=(student)o;
        return Double.compare(marks,p.marks);
    }
}
上一篇下一篇

猜你喜欢

热点阅读