Java inheritance - constructors

前端 未结 5 706
盖世英雄少女心
盖世英雄少女心 2021-01-02 04:22

While studying for my finals, I came across the following statement in the book from which I am currently studying. Considering the following code :

class A         


        
5条回答
  •  盖世英雄少女心
    2021-01-02 04:48

    It is neccessary to call constructor of super class in case of Java. Therefore, whenever you generate constructor of sub class, super class' constructor is self created by IDE.

    It is because whenever base class constructor demands arguments, compiler thinks they are to be filled by base class constructor. In case of default constructor, it is OK. No need to call super() in sub class.

提交回复
热议问题