Function overloading in Object Oriented Programming.

Function Overloading is the concept of object oriented programming in which we use same function name with different use.
In function overloading we use different parameter to differentiate with each other and this is the concept of Polymorphism feature of Object Oriented Programming.

EXAMPLE:

#include <iostream>
using namespace std;

class geopmetry 
{
public:
int area(int sideLength)    //same function name
{
return (sideLength*sideLength);
}
int area(int sideLength,int sideWidth) //same function name
{

return (sideLength*sideWidth);
}
int area(double sideLength)  //same function name
{
return (sideLength*sideLength*sideLength);
}
};
int main()
{
geopmetry geopmetryObj;
cout<<"area of square having length(10) ="<<geopmetryObj.area(10)<<"\n";
cout<<"area of rectangle having length(10),width(20) ="<<geopmetryObj.area(10,20)   <<"\n";
cout<<"volume of qube having length(10) ="<<geopmetryObj.area(10.0);
return 0;
}

Output:

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.