Function overloading : two or more than two function in a program with same name but must be different in parameters.
#include<iostream.h>
#include<conio.h>
class demo
{
public :
void add()
{
int a,b,c;
cout <<"enter any number";
cin >> a;
cout <<"enter any number";
cin >>b;
c=a+b;
cout <<c <<endl;
}
void add(int a,int b)
{
int c;
c=a+b;
cout << c <<endl;
}
};
main()
{
clrscr();
int a,b;
cin >> a;
cin >> b;
demo d1;
d1.add();
d1.add(a,b);
getch();
}
// Here in above program there are two add fuctions. One is of without parameters
// and second one is with parameters.
No comments:
Post a Comment