Why default constructor is required in a parent class if it has an argument-ed constructor?

后端 未结 12 1495
终归单人心
终归单人心 2020-11-29 21:17

Why default constructor is required(explicitly) in a parent class if it has an argumented constructor

class A {    
  A(int i){    
  }
}

class B extends          


        
12条回答
  •  旧巷少年郎
    2020-11-29 21:57

    I would guess that its because when you have an empty parameter list the super variable can't be instantiated. With empty parameter list I mean the implicit super() the compiler could add if the super class had a nonparametric constructor.

    For example if you type:

    int a;
    System.out.print(a);
    

    You will get an error with what I think is the same logic error.

提交回复
热议问题