Constructors

Constructors

Constructors are special class members which are called by the compiler every time an object of that class is instantiated. Constructors have the same name as the class and may be defined inside or outside the class definition.

There are 3 types of constructors:

Default constructors
Parametrized constructors
Copy constructors

// C++ program to demonstrate constructors

#include <iostream>
using namespace std;
class examp
{
// Access specifier
public:

// Data Members
int a;

// Member Functions()
examp()
{  a =10;
cout << “A = ” << a;
}
};

int main()

 {

// Declare an object of class geeks
examp obj1;

return 0;
}

Output:

A=10

error: Content is protected !!