C++ Constructor Overloading Program
In this tutorial, we will learn how to demonstrate the concept of Constructor Overloading, in the C++ programming language.
To understand the concept of Constructor Overloading in CPP, we will recommend you to visit here: https://www.studytonight.com/cpp/constructors-and-destructors-in-cpp.php, where we have explained it from scratch.
using namespace std;
//defining the class shape to overload the method area() on the basis of number of parameters.
//declaring member variables
int length, breadth;
// Constructor without argument
Area() : length(5), breadth(2)
// Defining a Constructor with two arguments: length and breadth
Area(int l, int b) : length(l), breadth(b)
cout << "\nEnter the Length and Breadth of the Rectangle : \n";
cin >> length >> breadth;
return (length * breadth);
void DisplayArea(int a)
cout << "Area of the Rectangle is = " << a << endl;
//Defining the main method to access the members of the class
cout << "\n\nWelcome to Studytonight :-)\n\n\n";
cout << " ===== Program to demonstrate Constructor Overloading in a Class, in CPP ===== \n\n";
Area a1; //Default constructor is called
Area a2(5, 2); //Parameterised constructor is called
int area1, area2;
cout << "\n\nCalculating Area using a Default Constructor:" << endl;
area1 = a1.AreaCalculation();
cout << "\n\nCalculating Area using a Parameterised Constructor:" << endl;
area2 = a2.AreaCalculation();
cout << "\n\nExiting the main() method\n\n\n";
We hope that this post helped you develop better understanding of the concept of Constructor Overloading in C++. For any query, feel free to reach out to us via the comments section down below.
Keep Learning : )