Pages

get our extension

Search program

Monday 12 August 2013

Difference between method overloading and method overriding

 Method Overloading
  Method Overriding
Writing two or more method with the same name but with different signature is called method overloading
Writing two or more method with the same name and same signature is called method overriding
method overloading is done in the same class
Method overriding is done in super and sub classes.
In method overloading, method return type can be same or different.
In method overriding, method return type should also be same.
JVM decides which method is called depending on the difference in the method signature.
JVM decides which method is called depending on the data type (class) of the object used to call the method.
Method overloading is done when the programmer wants to extend the already available feature.
Method overriding is done when the programmer wants to provide a different implementation (body) for the same feature.
Method overloading is code refinement. Same method is refined to perform a different task.
Method overriding is code replacement. The sub class method overrides (replaces) the super class method.

No comments:

Post a Comment