1.

Method Overloading vs Overriding

Answer»

In Method Overloading, the names of the methods in the same class are same but the arguments (TYPE and/or number) are DIFFERENT.
In Method Overriding, the names and arguments of the methods are same but one of the methods is in the super class while the other is in the sub class.

Basis
Method Overloading
Method Overriding
Arguments
The methods in overloading have different arguments.
The methods in overriding have similar arguments.
Polymorphism
Overloading is a part of compile time polymorphism
Overriding is a part of run time polymorphism.
Occurrence
Happens at compile time.
The binding of the OVERLOADED function CALLS it definition during compile time.
Happens at runtime. The binding of the overridden function calls its definition during runtime.
Static Methods
Static Methods can be overloaded.
Static methods cannot be overridden.
Class
Overloading is done in the same class
Overriding is done in the parent and child class.
Type of binding
Static binding is USED for overloaded methods
Dynamic binding is used for overridden methods
Performance
Method Overloading gives better performance as the binding is done during compile time.
Method Overriding gives less performance as the binding is done during runtime.
private methods
private methods can be overloaded.
private methods cannot be overridden.
final methods
final methods can be overloaded
final methods cannot be overridden.
Application
Method overloading is used to increase readability of the program
Method overriding is used to provide specific
implementation of the method
Return type
Return type of the methods does not matter during method overloading.
In method overriding, the method should have a specific return type.




Discussion

No Comment Found