Java constructor inheritance?

前端 未结 7 1999
一生所求
一生所求 2020-12-15 10:26

I always thought that constructors aren\'t inherited, but look at this code:

class Parent {
    Parent() {
        S         


        
7条回答
  •  既然无缘
    2020-12-15 11:06

    A constructor will always call its superclass constructor unless an explicit constructor has been defined. From the Java Language Specification:

    If a constructor body does not begin with an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body implicitly begins with a superclass constructor invocation "super();", an invocation of the constructor of its direct superclass that takes no arguments.

提交回复
热议问题