Tuesday, 17 November 2015

What is Constructor ? What are the rules of constructor

Constructor: It is a special type of method that is used to initialize the object. 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.
    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)
    parameterized constructor
 

No comments:

Post a Comment