Difference between Overloading and Overriding?

Overloading: Overloading happens when two or more function have the same function name but different return type and parameter.
eg:

int sum(int a int b);
int sum(int a int b int c);

The overloading happens in the same class i e these function should be in the same class.
Return type, Parameter type, parameter and body of method number may be different.
Overriding: It happens in inheritance when base class has a function called “int sum(int a int b)” and the derived class also has the function “int sum(int a int b)“. In this case we can’t access the base class class function by just creating an object of derived class.
If the base class function has the keyword Virtual then it means that the function should be override and we use the keyword Override.
Return type, Parameter type, Parameter Number all must be same. Only body of method can change.

Tagged . Bookmark the permalink.

Leave a Reply