What is the function of super in a Java constructor?

11

I have a child class that inherits from another abstract class, and the one in the class constructor has the following:

Public aluno(String nome, int idade){
    super(nome,idade);
}

What is the "super" function in the class constructor?

    
asked by anonymous 24.12.2014 / 12:34

2 answers

14

Call the constructor of the parent class. If this class is composed at least in part by another inherited class, this part also needs to be initialized and this is the way to initialize.

Let's think the class would be:

class Aluno extends Pessoa

Then super is calling a constructor of class Pessoa that has the appropriate signature to receive the name and age of the person that was obtained through the Aluno constructor.

    
24.12.2014 / 12:40
-4

When we have objects and make one class inherit the characteristics of another, using "extends", it is necessary to create the constructors, but many of them by question of elegance are defined with the same name as the parent class or superclass, so that we can differentiate to what we refer to, we use "this" for the subclass and "super" for the superclass.

    
24.12.2014 / 13:05