Constructors are special functions that are used to initialize the member of any class.
A pseudo-method that creates an object. In the Java programming language, constructors are instance methods with the same name as their class.
Constructors are invoked using the new keyword.
It is called when the instance of the class is created.
• Class name must be same as constructor name.
• There is not any explicit return type.
Defining a Constructor in Java
A simple Java constructor declaration example. In which a class with single constructor -
Types of Constructors-
Default constructor - When constructor does not have any parameter then it is called as default parameter.
Example to define Default Constructor -
Parameterized constructor - A constructor with arguments is known as parameterized constructor.
Example to define Parameterized Constructor -