Java constructor inheritance?

前端 未结 7 1972
一生所求
一生所求 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:18

    Java doc says :

    A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

    If you don't declare a constructor of any type, a default is added.

    If you don't call any other constructor in the first line of your subclass, a call to super() is made.

    0 讨论(0)
提交回复
热议问题