Home CPP Examples C++ Program to implements Constructor Overloading

C++ Program to implements Constructor Overloading

by anupmaurya
19 minutes read

Let’s see an program to implements constructor overloading.

// overloading class constructors
 #include<iostream>
 using namespace std;
 class Rectangle 
 {
 int width, height;
 public:
 Rectangle ();
 Rectangle (int, int);
 int area (void) 
   {
 return (width * height);
 }
 };
 Rectangle::Rectangle () 
 {
 width = 5;
 height = 5;
 }
 Rectangle::Rectangle (int a, int b) 
 {
 width = a;
 height = b;
 } 
 int 
 main () 
 {
 Rectangle rect (3, 4);
 Rectangle rectb;
 cout << "rect area: " << rect.area () << endl;
 cout << "rectb area: " << rectb.area () << endl;
 return 0;
 }

Output

react area: 12
reactb area: 25


			
            

			        

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.