class Person
{
private int age;
//设置
public void setAge(int a)
{
if(a>0 && a<130)
{
age=a;
speak();
}
else
System.out.println("what");
}
//获取
public int getAge()
{
return age;
}
void speak()
{
System.out.println("age="+age);
}
}
class PersonDemo
{
public static void main(String[] args)
{
Person p=new Person();
p.setAge(10);
}
}
获取方式又应该怎么用 |
|