How does the default Java constructor work?

7

How is the default Java constructor? Is this?

public Pessoa(){
    super();
}
    
asked by anonymous 02.10.2014 / 18:16

1 answer

9

The default constructor ( default constructor ) is the one the compiler creates for you. If you create it, it is not the default. You can even simulate a default :

public Pessoa() { super(); }

This is the way a default constructor is set up for you when you do not create it. The default constructor never has parameters and has nothing in the body other than a reference to the upper class. It exists just to start creating the object, it does nothing.

Actually calling super() in this case is unnecessary . See also: What is the role of super in a Java constructor? .

You are in language specification .

More about builders .

    
02.10.2014 / 18:19