Method Overloading Vs Overriding in Java

In our previous tutorials we have explained about the method overloading and method overriding in Java. Read those tutorials for the more explanations. This tutorial highlights the only differences and when we have to use both the concepts. Both the concepts are based on the polymorphism in Java. Look at the below table for the list of differences between method overloading and overriding in Java.

Method OverloadingMethod Overriding
1) Overloading is resolved using the static binding at compile timeMethod overriding is resolved at dynamic binding at run time.
2) Overloading should have same method name with different type or number of parametersOverriding should have same method name and number of parameters with exact same signature.
3) Return type is not considered for the method overloading.Return type must be same for the method overriding.
4) Overloading is performed within a same classOverriding is performed within two classes that have IS-A relationship
5) Static methods can be overloadedStatic methods can not overridden
6) Access specifier is not important for overloading. It can be anything.Same or Widen access specifier is accepted for the overriding. If parent class has public access, the child class can not override that method with protected. It must be public method.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!