A constructor in Java is a special method that is used to initialise objects. The constructor is called when an object of a class is created. It can be used to set initial values for object attributes.
File Name - Constructor_test.java
Output -
Java compiler automatically creates a default constructor (Constructor with no arguments) in case no constructor is present in the java class. Following are the motive behind a default constructor.
- Create the Object
- Call the super class constructor()
- Initialize all the instance variables of the class object.
File Name - Constructor_test.java
Output -
0 comments: