为实现对Student类中age的封装,使用了setage(),想实现当年龄不在一定范围内是提示输入错误并重新输入,重新输入我想通过再次运行setage()来实现,用this会出错,可是应该怎样操作?代码如下:public void setAge(int age) {
if(this.age<15)
{
System.out.println("输入有误,请重新输入");
//this.setAge(int age);
}
else
this.age = age;
}
既然是输入有误,为何还要保存?!!