javasuper

super() in Java


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


Solution

  • 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