美文网首页
compareTo方法的实现

compareTo方法的实现

作者: 地表最强程序员小白 | 来源:发表于2017-11-11 21:26 被阅读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);
        }
    }
    

    相关文章

      网友评论

          本文标题:compareTo方法的实现

          本文链接:https://www.haomeiwen.com/subject/zjugmxtx.html