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.
but different method signatures, which mean the methods
are overloaded
4.Overloading lets you define the same operation in
different ways for different data.
the other one in the child class and has the same name and
signatures.
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.
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 andthe 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