<<< When is constructor called ? | Index | Inside a Constructor >>> |
In Java keyword new creates a new instance of an object:
Planet saturn = new Planet(); // Java code
Empty parentheses in the above code specify that constructor of the Planet class does not take any arguments.
Constructor with no parameters is called default constructor.
Alternatively, constructors could have a list of parameters required to properly initialize the object.
<<< When is constructor called ? | Index | Inside a Constructor >>> |