class People
{
private /*私有的*/ int age;
public void setAge(int x)
{
if(x<0 || x>130)
System.out.println("错误的数据");
else
age = x;
}
public int getAge()
{
System.out.println("age="+age);
return age;
}
}
class PeopleDemo
{
public static void main(String[] args)
{
People a = new People();
a.setAge(11);
a.getAge();
}
}
|
|