Example & Tutorial understanding programming in easy ways.

What is the difference between function overloading and function overriding in C++ programming language?

Difference between function overloading and overriding:
-In function overloading, number of parameter in function may be different but in function overriding parameter are same.
-Function overloading are done in only one class while function overriding is deal with two class.
-Function overloading is the example of static polymorphism while function overriding is the example of dynamic polymorphism.

Function overloading:

program:

#include < iostream>
using namespace std;
class r4r
{
public:
int sum(int a,int b, int c)
{
cout<<"Sum is: "<< a+b+c<< endl;
}
int sum(int a,int b)
{
cout<<"Sum is: "<< a+b<< endl;
}
int sum(double a,double b)
{
cout<<"Sum is: "<< a+b<< endl;
}
};

int main()
{
r4r obj;
obj.sum(2,3,4);
obj.sum(1,2);
obj.sum(3.2,4.1);
return 0;
}


output-

Sum is: 9
Sum is: 3
Sum is: 7.3
Function overriding:

program:


#include
using namespace std;
class parent {
public:
void func(){
cout<<"This is my parent function";
}
};
class child: public parent
{
public:
void func()
{
cout<<"Child function";
}
};
int main(void) {
child d = child();
d.func();
return 0;
}


output-


Child function




Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!