package test;
public class Person {
String name; private int age;
public void show(){
System.out.println("我的名字是"+name+",我今年"+age+"岁.");
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return this.age;
}
public int compare(Person p){//类名作为参数传递的类型
if(p.age==this.age){
return 0;
}
return 1;
} }
public class PersonDemo {
public static void main(String[] args) {
Person p1=new Person();
p1.setAge(20);
Person p2=new Person();
p2.setAge(30);
int x=p1.compare(p2);//类作为参数类型的测试
System.out.println(x);
} }
网友评论