Monday, April 5, 2021

constructor overloading (OOP) (18)

     /*constructure overloading

                             **************************/


#include<iostream>

using namespace std;

class overloading               //constructure should be with same name but different parametters is 

                                //calllad constructure overloading

{

private:

int a,b;

public:

overloading() //default constructure

{

a=0;

b=0;

}

overloading(int x) //parameterized constructure

{

a=x;

}

overloading(int x, int y)  //parameterized constructure

{

a=x;

b=y;

}

void display()

{

cout<<"the value of a:"<<a<<endl;

cout<<"the value of b:"<<b<<endl;

}

};

int main()

{

overloading o1;

overloading o2(12);

overloading o3(55,65);

o1.display();

o2.display();

o3.display();

} 

No comments:

Post a Comment