java4all@1986 java. Powered by Blogger.

Difference between Method Overloading and Method Overriding?

>> Monday, May 30, 2011

Method Overloading :
1.Overloading deals with multiple methods in the same class
with the same name but different method signatures.
2.
class MyClass {
public void getInvestAmount(int rate) {…}
public void getInvestAmount(int rate, long principal)
{ … }
}
3.Both the above methods have the same method names
but different method signatures, which mean the methods
are overloaded
4.Overloading lets you define the same operation in
different ways for different data.
Method Overriding:
1.Overriding deals with two methods, one in the parent class and
the other one in the child class and has the same name and
signatures.
2.class BaseClass{
public void getInvestAmount(int rate) {…}
}
class MyClass extends BaseClass {
public void getInvestAmount(int rate) { …}
}
3.Both the above methods have the same method names and
the signatures but the method in the subclass MyClass
overrides the method in the superclass BaseClass.
4.Overriding lets you define the same operation in different
ways for different object types.

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP