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.



About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind