In this program, You will learn how to implement default constructor in C++.
Default constructor in C++
Test() { }
#include<iostream>
using namespace std;
class Test {
public:
int a;
Test() {
cout << "Enter a Number :";
cin >> a;
}
void display() {
cout << "\nValue of a is :" << a;
}
};
int main() {
Test obj;
obj.display();
return 0;
}
Enter a Number :12
Value of a is :12