Constructors are functions of a class that are executed when new objects of the class are created. The constructors have the same name as the class and no return type. They are primarily useful for providing initial values for variables of the class.
The two main types of constructors are default constructors and parameterized constructors.
A program that constructors is given as follows.
#include<iostream>
using namespace std;
class A {
public:
A()
{
cout<<" The Constructor !! ";
}
};
int main(){
A obj; //When create a object constructor are called
}
Output:
The Constructor !!
0 Comments
Thanks for Supporting me