Overloading and Overriding difference in Java - Java @ Desk

Monday, March 3, 2014

Overloading and Overriding difference in Java

Overloading and Overriding difference in Java

In our last two posts, we have understood the basics of Method Overriding in Java and Method Overloading in Java.

There are good number of difference between the two as :
1) private method cannot be overridden but private method can be overloaded
2) final method cannot be overridden but private method can be overloaded
3) static method cannot be overridden but private method can be overloaded
4) Overriding is decided at runtime where as overloading is decided at compile time
5) Overriding is decided by the actual object type where as overloading is decided by the reference type
6) In overriding, the method name & number of arguments & type of arguments & ordering or arguments must be same where as in case of overloading, method name & return type must be same
7) Overriding method can not throw higher Exception than original or overridden method where as overloaded method can throw narrower exception







No comments:

Post a Comment