Sunday 22 June 2014

Difference Between Method Overloading and Overriding

Difference Between Method Overloading and Overriding


Method Overloading

Method Overriding
1. Method name must be same. 1. Method name must be same.
2. Method argument must be different. 2. Method arguments must be same.
3. Method signature must be different. 3. Method signature must be same.
4. Return type can be changed. 4. Return type must be same until 1.4v but after 1.5v co-variant type allowed.
5. Private , static and final method can be overloaded. 5. Private , static and final method can not be override.
6. Any type of access modifier is allowed(public ,  protected , private). 6. We can not decrease the scope modifier.
e.g. public method can not override as  protected.
7. There is no restriction in exception handling. 7. Child class should be handle exception same as the parent class or the child exception.

e.g. P: Exception
C: Exception or IOException
8. Method resolution takes by the compiler. 8. Method resolution takes by the JVM based on the object reference.
9. Method overloading also known as static polymorphism, compile-time polymorphism or early binding 9. Method overriding also known as dynamic polymorphism, run-time polymorphism or late binding




0 comments :

Post a Comment