- Default
- Parameterized
- Copy
Default Constructor is also known as zero argument constructor, as it doesn't take any parameter. It can be defined by the user if not, then the compiler creates it on its own.
class_name{
//body
}
#include <iostream>
using namespace std;
class student{
int roll;
string name;
public:
student() { //default constructor
cout << "Enter the roll no: ";
cin >> roll;
cout << "Enter the name: ";
cin >> name;
};
void display() {
cout << "Roll no = " << roll << endl;
cout << "Name = " << name;
};
};
int main() {
student std;
std.display();
return 0;
}