本文主要是介绍day6 test10,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package day6;class PersonA
{private String name;private int age;public PersonA(String name, int age){this.name = name;this.age = age;}@Override //注解: 告诉编译器下面的方法是重写父类的public boolean equals(Object obj){//this objif(this == obj)return true;if(obj instanceof PersonA){PersonA p = (PersonA) obj;//this pif(this.name.equals(p.name) && this.age==p.age)return true;}return false;}
}public class test10 {public static void main(String args[]){PersonA p1 = new PersonA("zhangsan", 19);PersonA p2 = new PersonA("zhangsan", 19);PersonA p3 = p1;PersonA p4 = new PersonA("wangwu", 21);System.out.println(p2.equals(p4));}
}
这篇关于day6 test10的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!