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 Overloading | Method Overriding |
---|---|
1) Overloading is resolved using the static binding at compile time | Method overriding is resolved at dynamic binding at run time. |
2) Overloading should have same method name with different type or number of parameters | Overriding 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 class | Overriding is performed within two classes that have IS-A relationship |
5) Static methods can be overloaded | Static 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. |