菜鸟求助:类的封装性,看我错在哪儿
class Person
{
private int age;
public void setAge(int i)
{
if(i<0||i>130)
return;
age=i;
}
public int getAge()
{
return age;
}
}
public class TestPerson
{
public static void main(String[] args)
{
Person p1=new Person();
p1.setAge(3);
p1.setAge(-6);
System.out.println(p1.getAge());
}
}
运行不了啊,望各位大侠指点,由于我是新手,有的地方也请稍加解释