Programming Language

Overriding and Overloading: A Comparison

A very frequent confusion in the mind of java programmers is about Method Overloading and Method Overriding. These two, although quite simple to understand are related in such a way that they always confuse programmers, so this description will help out those programmers significantly in removing that glitch

Method Overloading:

In java programing, Method Overloading (termed as overloading later) occurs when two or more than two methods in a similar class are assigned identical names but they differ in their limitations/parameters.

Method Overriding:

It is quite a different process in java programming that is used when an acquired class requires some different definition for an obtained or inherited class. The overridden method will have an exact same method name, number of limitations, return type and parameter types as they were in the parent class.

Comparison:

Method Overloading Method Overriding
It occurs at the time of code compilation. It happens at the runtime of program.
It  can happen with the static methods i.e. a class can be having greater than one static methods of same name. Cannot happen with static methods I.e. the static method defined in child class has got nothing to do with the parent class and vice versa.
Overloading is basically done in the same class of coding. For overriding, two classes i.e. parent and child class of coding are mandatory.
Return type does not matter. Return type matters.
 The argument list in doing overloading should be different.  The argument list in doing overriding should be same.

 

The binding technique used for overloading is Static Binding, while for overriding Dynamic Binding technique is used.

Performance of Method Overloading is better when compared to overriding because patching of overridden methods is performed at runtime.

To summarize the comparison, we can say that when using overloading method, the programmer has to change either the types or the number of parameters they use for a specific same class. Whereas, in using overriding method, everything except definition of method step remains same as it is.

In terms of usability, overloading is basically used to enhance readability of any specific program. Method overriding is specifically used to implement a specific operation which is supervised by the superclass.

Leave a Reply