?java——equals

2019年2月16日21:33:01 发表评论 1,128 views
/**
 * Created by xabcd on 2019/2/16.
 */
public class person_equals
{
    private String name;
    private int age;
    public person_equals(String name,int age)
    {
        this.name = name;
        this.age = age;
    }
}




/**
 * Created by xabcd on 2019/2/16.
 */
public class test_equals1
{
    public static void main(String[] args) {
        person_equals p1 = new person_equals("张三", 25);
        person_equals p2 = new person_equals("张三", 25);
        System.out.println(p1.equals(p2) ? "是同一个人" : "不是同一个人");
    }

}





结果:
不是同一个人

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: