Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation.It constructs the value i.e. provides data for the object that is why it is known as constructor.
Rules for creating java constructor:
>Constructor name must be same as its class name.
>Constructor must have no explicit return type.
There are two types of constructors:
Default constructor (no-arg constructor)
Constructor that have no parameter is known as default parameter.
|e.g. of default constructor, we are creating the no-arg constructor in the Bike class. It will be invoked at the time of object creation.|
Bike is created.
A constructor that have parameter is known as parameterized constructor.
| example, we have created the constructor of Student class that have two parameters. We can have any number of parameters in the constructor.|