Constructor Overloading Example in C++

Example Program:

Here is the simple program for printing the area of rectangle using constructor overloading in C++.

Source Code

using namespace std;
class Area
    int length;
    int breadth;
    Area(): length(5), breadth(2) { }
    Area(int l, int b): length(l),breadth(b){ }
    void GetLength()
       cout<<"\nEnter length of the Rectangle: ";
       cout<<"\nEnter breadth of the Rectangle: ";
    int Calculation()
      return length*breadth;
    void Display(int temp)
       cout<<"Area: "<<temp<<endl;
int main()
    Area A1, A2(2,1);
    int temp;
    cout<<"\nDefault Area when no argument is passed."<<endl;
    cout<<"\nArea when (2,1) is passed as argument."<<endl;
    return 0;
To download raw file Click Here


Default Area when no argument is passed.
Area: 10

Area when (2,1) is passed as argument.
Area: 2

Basic Programs

Flow Control

IF Statement Examples

Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++

String Examples

Array Examples

Structure Examples

Structure & Pointer Examples

Structure & Functions Examples

Enumeration Examples

Template Examples


Inheritance Examples

Hierarchical Inheritance

Hybrid Inheritance

Multilevel Inheritance

Multiple Inheritance

Single Level Inheritance

Class and Objects

Constructor Example

Destructor Example

Operator Overloading Example

Operator and Function Example

List of Programs

Pointer Examples

Memory Management Examples

Pointers and Arrays

Virtual Function Examples

Learn All in Tamil © Designed & Developed By Tutor Joes