package com.kiloPhone.tenthClass;
class Person {
String name;
int age;
long phoneNum;
String address;
public Person(String name, int age, long phoneNum, String address) {
super();
this.name = name;
this.age = age;
this.phoneNum = phoneNum;
this.address = address;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Person) {
Person p = (Person) obj;
if (this.name.equals(p.name) && this.age == p.age
&& this.phoneNum == p.phoneNum
&& this.address.equals(p.address)) {
return true;
}
}
return false;
}
}
public class TestEquals {
static void print(Object o) {
// Object o = new String();
System.out.println(o);
}
public static void main(String[] args) {
Person p1 = new Person("山", 25, 18810395565L, "北京市昌平区回龙观");
Person p2 = new Person("山", 25, 18810395565L, "北京市昌平区回龙观");
System.out.println(p1.equals(p2));
print(p1);
}
}
Equals
最新推荐文章于 2022-05-08 19:42:31 发布