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);
      }
    }
      
  • 相关阅读:
    Express 2015 RC for Windows 10 安装
    离线下载Express 2015 for Windows 10
    离线下载Express 2015 for Windows 10
    windows 10预览版升级win10 7月29 10240.16384
    windows 10预览版升级win10 7月29 10240.16384
    C# 获得系统环境
    C# 获得系统环境
    C++宽字符串转字符串
    C++宽字符串转字符串
    C++ md5类,封装好
  • 原文地址:https://www.cnblogs.com/lxy151/p/8136368.html
Copyright © 2011-2022 走看看