answersLogoWhite

0

A constructor is a function defined in a class with the name same as the class name and is used to automatically initialized the class data members. It is never preceded by a return type not even void.

eg -

class abc

{

int a, b;

abc() //constructor

{

a=0;

b=0;

}

};

main()

{

abc a;

}

The time we create object of the class in the main function the data members of the class are automatically initialised.

Constructor can even take parameter. Those constructor are known as parameterised constructor.

User Avatar

Wiki User

12y ago

What else can I help you with?