While constructing the default constructor can not handle exception : type Exception thrown by implicit super constructor

后端 未结 4 571
独厮守ぢ
独厮守ぢ 2020-11-29 10:19

The code works fine until I try to make the code into a constructable class. When I attempt to construct an object from it I get the error

\"Default

4条回答
  •  星月不相逢
    2020-11-29 10:55

    Default constructor implicitly invokes super constructor which is assumed to be throwing some exception which you need to handle in sub class's constructor . for detailed answer post the code

    class Base{
    
      public Base() throw SomeException{
        //some code
      }
    
    }
    
    class Child extends Base{
      public Child(){
       //here it implicitly invokes `Base()`, So handle it here
      }
    }
    

提交回复
热议问题