package org.classdemo;
class Person{
private String name;
private int age;
public Person(){
}
public Person(String n,int a){
this.setName(n);
this.setAge(a);
}
public void setName(String n){
this.name = n;
}
public void setAge(int a){
if (a>0){
this.age = a;
}else{
this.age=1;
}
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public boolean Compare(Person p){
if (this == p){
return true;
}
if (this.name.equals(p.getName()) && this.age == p.getAge()){
return true;
}else{
return false;
}
}
}
public class comparedemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p1 = new Person();
Person p2 = new Person();
p1.setName("张三");
p1.setAge(20);
p2.setName("张三");
p2.setAge(20);
if (p1.Compare(p1)){
System.out.println("类一致");
}else{
System.out.println("类不一致");
}
}
}