那你就在super(name,age);语句后面加上检查语句不就行了吗?

解决方案 »

  1.   

    public Student(String name,int age,long stuid)throws ...{
    super(name,age);
    this.stuid = stuid
    }
    再抛出去,不能让子类把异常给吃了
      

  2.   

    public Student(String name,int age,long stuid) throws IllegalArgumentException{
        super(name,age);
        if(age>100 || age<0) throws new IllegalArgumentException("年龄值异常:" + age);
        this.stuid = stuid;
    }
      

  3.   

    你可以把父类的构造函数改造一下:  
    public Person(String name,int age){
        if (age>1 && age<100)
        {
        this.name = name;
        this.age = age;
        }
       else{}
      }