When do you need to explicitly call a superclass constructor?

后端 未结 3 1714
忘掉有多难
忘掉有多难 2020-11-27 12:46

So say I have a subclass that extends a superclass. In what scenarios do I need to explicitly type super() to get the superclass constructor to run?

I\

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 13:28

    The super() method is always called in constructors of sub-classes, even if it is not explicitly written in code.

    The only time you need to write it, is if there are several super(...) methods in the super-class with different initialization parameters.

提交回复
热议问题