In this section we are going to discuss the difference between method overloading and method overriding. Firstly understand the definition of both terms in brief:
Method overloading refers to a concept in which we have more than one method with a same name but differ in the number or types of parameters within a same class.
Method overriding refers to a concept in which we redefine the method in child class with same name, same return type and same parameter list as its parent class method.
Method Overloading |
Method Overriding |
Method overloading is used to increase the readability of the program. | Method overriding is used to give the specific implementation of the method that is already provided by its parent class. |
Method overloading is done within class. | Method overriding occurs in two classes that have IS-A relationship. |
In case of method overloading, parameter must be different. | In case of method overriding, parameter must be same. |
Method overloading is the example of compile time polymorphism. | Method overriding is the example of run time polymorphism. |
Method overloading cannot be performed by changing return type of the method only. Return type can be same or different, but there must change in the parameter. | Return type must be same or covariant in method overriding. |
In method overloading, you can overload method in same class. | In method overriding, you can only override method in child class. |
In method overloading, you can overload static method in Java | In method overriding, you cannot override static method in Java. |
In method overloading, private and final method can be overloaded in Java. | In method overriding, private and final method cannot be overridden in Java. |
It may or may not need inheritance in Method Overloading. | It always requires inheritance in Method Overriding. |