Wednesday, 31 January 2018

What is method overloading and method overriding?


Method Overloading : -In Method Overloading, Methods of the same class shares the same name but each method must have different number of parameters or parameters having different types and order.
-Method Overloading is to “add” or “extend” more to method’s behavior.
-It is a compile time polymorphism.
-The methods must have different signature.
-It may or may not need inheritance in Method Overloading
Method Overriding: -In Method Overriding, sub class have the same method with same name and exactly the same number and type of parameters and same return type as a super class.
-Method Overriding is to “Change” existing behavior of method.
-It is a run time polymorphism.
-The methods must have same signature.
-It always requires inheritance in Method Overriding.

No comments:

Post a Comment