Skip to main content

Posts

Showing posts with the label constructor overloading example

write a program to demonstrate constructor overloading.

 Here's an example program that demonstrates constructor overloading in C++: #include <iostream> using namespace std; class Rectangle {    private:     int length, width;    public:     // Default constructor     Rectangle() {         length = 0;         width = 0;     }     // Parameterized constructor with one argument     Rectangle(int l) {         length = l;         width = l;     }     // Parameterized constructor with two arguments     Rectangle(int l, int w) {         length = l;         width = w;     }     // Method to calculate and return the area of the rectangle     int area() {         return length * width;     } }; int main() {     // Create objects of Rectangle cla...