class day05
{
public static void main(String[] args)
{
//输入年龄并打印
GouZao gz = new GouZao(30);
System.out.println(gz.getAge());
gz.setAge(160);
System.out.println(gz.getAge());
//比较两人年龄是否相同
GouZao p1 = new GouZao(33);
GouZao p2 = new GouZao(40);
System.out.println(p1.compare(p2));
}
}
class GouZao
{
{
System.out.println("我是构造代码块...");
}
private int age;
GouZao(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
public boolean compare(GouZao gz)
{
return this.age == gz.age;
}
public void setAge(int age)
{
if (age < 150 && age > 0)
{
this.age = age;
}
else
{
this.age = -1;
System.out.println("你不是人...");
}
}
}