zoukankan      html  css  js  c++  java
  • 简单java类比较

     

    class Che{
      private String name;
      private double price;
      public Che(){}
      public Che(String name,double price){
        this.name = name;
        this.price = price;
      }
      public String getName(){
        return name;
      }
      public void setName(){
        this.name = name;
      }
      public double getPrice(){
        return price;
      }
      public void setPrice(double price){
        this.price = price;
      }
      public String getInfo(){
        return "车名:"+name+"价格:"+price;
      }
      public boolean compare(Che che){
        if(che==null){ return false;}
        if(che==this){ return true;}
        if(this.getName().equals(che.getName()) && this.getPrice()==che.getPrice()){
          return true;
        }
        return false;
      }
    }
    class Statt {
      public static void main(String[] args) {
        Che c1 = new Che("大众",100000.0);
        Che c2 = new Che("大众",100000.0);
        Che c3 = new Che("奔驰",2000000.0);
        //System.out.println(c1==c2); 
        //System.out.println(c2==c3); 
        //if(c1.getName().equals(c2.getName()) && c1.getPrice()==c2.getPrice()){
        //    System.out.println("c1和c2相等");
        //}else{
        //    System.out.println("错误");
        //}
        System.out.println(c1.compare(c2));
        System.out.println(c1.compare(c3));
        System.out.println(c1==null);
        System.out.println(c1==c1);
      }
    }
      
  • 相关阅读:
    Oracle
    Oracle11g服务详细介绍及哪些服务是必须开启的?
    数据结构——二叉树树的遍历理论与实现
    MapReduce新版客户端API源码分析
    【编程范式】汇编解释swap方法
    iPhone、iPod和iPad离线固件升级的方法
    Linux备份
    mysql下用户和密码生成管理
    The secret of ROWID
    linux文件权限解说
  • 原文地址:https://www.cnblogs.com/lxy151/p/8136368.html
Copyright © 2011-2022 走看看