Difference between method Overloading and Overriding.
Overloading 1) method overlaoding is occurs within the class. 2)Method overloading increases the readability of the program 3) In this case, parameter must be different. 4)It is a compile time polymorphism. 5)In Method Overloading, relationship is there between methods of same class. 6)It may or may not need inheritance in Method Overloading. |
Overriding. 1)Method overriding occurs in two classes that have IS-A relationship. 2)Method overriding provides the specific implementation of the method that is already provided by its super class. 3)In this case, parameter must be same. 4)It is a run time polymorphism. 5)In Method Overriding, relationship is there between methods of super class and sub class. 6)It always requires inheritance in Method
Overriding. |
example: Overloading & Overriding.
Overloading.. Class test{ int add(int a, int b){ return a + b;} int add(int a) // method overloading { return a + 3; }} |
Overriding..
public
class test{ public
int rock() { return 3;}} public
class jtest
extends test{ public
int rock()
// this is method overriding:{ return 7;}} |