Why can't this() and super() both be used together in a constructor?

后端 未结 9 665
栀梦
栀梦 2020-12-12 17:17

Why can\'t this() and super() both be used together in a constructor?

What is the reason for incorporating such a thing?

9条回答
  •  半阙折子戏
    2020-12-12 17:48

    There is a difference between super() and this().

    super()- calls the base class constructor whereas
    this()- calls current class constructor.

    Both this() and super() are constructor calls.
    Constructor call must always be the first statement. So you either have super() or this() as first statement.

提交回复
热议问题