What is constructor in java?
1612
26-Mar-2015
Anonymous User
26-Mar-2015Constructor 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 values i.e. provides data for the object that is why it is known as constructor.
There are basically two rules defined for the constructor.
1.Constructor name must be same as its class name
2.Constructor must have no explicit return type
There are two types of constructors:
1-Default constructor (no-arg constructor)
2-Parameterized constructor