super() in Java

前端 未结 15 2219
逝去的感伤
逝去的感伤 2020-11-22 05:36

Is super() used to call the parent constructor? Please explain super().

15条回答
  •  春和景丽
    2020-11-22 05:50

    super() calls the parent constructor with no arguments.

    It can be used also with arguments. I.e. super(argument1) and it will call the constructor that accepts 1 parameter of the type of argument1 (if exists).

    Also it can be used to call methods from the parent. I.e. super.aMethod()

    More info and tutorial here

提交回复
热议问题