Overloading & Overriding

what is the difference between overloading & overriding ?

Overriding - same method names with same arguments and same return types associated in a class and its subclass. 
Overloading - same method name with different arguments, may or may not be same return type written in the same class itself. 

Example for overriding :

 Clas A
Virtual void hi(int a)
Class B:A
public overrid void hi(int a)
 Example for Over loading :

 Class A
class a()
class a(int a)

How OverLoading is different from Overriding :

Overloading comes when you define two methods or morethan two methods with the same name in the same class with different signature.

Overriding comes when you redefine a method that has already been defined in a parent class with ther same signature.

Overloading is resolved at compiletime .

Overriding is resolved at runtime.

simply we can tell like Overloading deals with multiple methods in the same class with the same name but different signature where as overriding deals with two methods one is in parent class and another one is in derived class that have the same signature, means when you override, you change the method behaviour for a child class.


1.Same name but there are different definitions and parameters..

2.Here, the definitions are extented.

3.Seperate methods share the same name.

4.It is mainly for operators.

5.It must have different method signatures.


1.Here replacement of methods.

2.It is used in inheritance.

3.subclass methods replaces the superclass.

4.It is mainly for functions.

5.It must have same signature

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s