首页 > 其他 > 详细

对象比较

时间:2017-09-03 13:00:45      阅读:271      评论:0      收藏:0      [点我收藏+]

对象比较就是两个对象的属性进行比较

对象比较的实现形式一

class Person

{

  private String name ;

  private int age ;

  public Person(String name , int age)

  {

   this.name = name;

   this.age = age; 

  }

  public String getName() {

    return this.name;

  }

  

public int  getAge() {

    return this.age;

  }

}

public class Testdemo{

  public static void main(String args[]){

  Person perA = new Person("张三",20);

  Person perB= new Person("张三",20);

  System.out.println(perA == perB);       //需要根据对象拥有的属性信息来进行比对

  if (perA.getName().equals(perB.getName()) && perA.getAge() == perB.getAge()) {

    System.out.println("")

  }

  }  

}

对象比较

原文:http://www.cnblogs.com/123talents/p/7469175.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!