What is the difference between method overloading and overriding in Java?
#
|
Method Overloading
|
Method Overriding
|
1.
|
Method
Overloading occurs during compile time.
|
Method
Overriding occurs during runtime.
|
2.
|
We
can overload method in the same class
|
We
can only override a method in a subclass.
|
3.
|
We
can overload static method in Java
|
We
cannot override static method in Java
|
4.
|
Overloaded methods are bonded using static binding and Type of a reference variable is used
|
An overridden method is bonded using dynamic bonding based upon actual Object.
|
5.
|
In order to overload
a method you need to change its method signature
|
. In order to override a method that is not required to
change its method signature in a subclass.
|
6.
|
a private and final method can be overloaded
|
a private and final method cannot be overridden
|
7.
|
An overloaded method is fast
|
An overridden method is slow as compare to Overloaded method.
|
No comments:
Post a Comment