Define Constructor ????
With example............
Answers
Answered by
0
How construct a thing is known as constructor
Ex. The mason is constructor of our house
Ex. The mason is constructor of our house
siddhartharao77:
^_^
Answered by
2
A constructor is a special method that builds the instance of an object when a new object is created.
(or)
The constructor is called whenever a new object is created.
Constructor name will be same as the name of the class and they never have a return type.
Following is the example of the constructor:
Class Demo
{
public :
int a,b;
Demo()
{
a = 100;
b = 200;
}
};
int main()
{
Demo d;
cout << "a: "<< d.a << endl << "b: "<< d.b;
return 1;
}
Hope this helps!
(or)
The constructor is called whenever a new object is created.
Constructor name will be same as the name of the class and they never have a return type.
Following is the example of the constructor:
Class Demo
{
public :
int a,b;
Demo()
{
a = 100;
b = 200;
}
};
int main()
{
Demo d;
cout << "a: "<< d.a << endl << "b: "<< d.b;
return 1;
}
Hope this helps!
Similar questions
Science,
8 months ago
Science,
1 year ago
Social Sciences,
1 year ago
Physics,
1 year ago
Hindi,
1 year ago