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);
      }
    }
      
  • 相关阅读:
    学习笔记之C++ How to Program(part)
    Makefile相关资料
    [ZZ]指针Guide
    [ZZ]make命令与makefile文件的写法
    SQLite数据库简介及资源下载
    程序员天生码农命?
    Application标签中有三个事件运行顺序
    Flex 项目案例集锦
    flex简介
    Flex连接数据库三种方法
  • 原文地址:https://www.cnblogs.com/lxy151/p/8136368.html
Copyright © 2011-2022 走看看