Difference between method overloading and method overriding

ParameterMethod OverloadingMethod Overridding
1)DefinationWhen a class having more than methods with same name but change in signature then method is said to be overloaded.Method overriding means providing subclass specific implementation for the inherited method.
2)SignatureSignature should be different.Method signature means Number of parameter should be different, Order of parameter should be different, Sequence of parameter should be different.Signature Should be same.
3)Return typeReturn type of overloaded method may or may not be same.Return type of overridded method should be same
4)Access modifierAccess modifer of overloaded methods can be anythingAccess modifier of overrided method must be same or higher visibility
5)PolymorphismMethod overloading is called as Compile time polymorphismMethod overridding is called as Run time polymorphism
6)ScopeMethod overloading is performed within a classMethod overridding is perform between two classes or between interface and class through inheritance
7)ContructorContructor can be overloadedContructor can not be override because we can not inheritate the contructor.
8)Private MethodPrivate method can be overloadedPrivate method can not be override
9)Static MethodStatic method can be overloadedStatic method can not be override
10)final Methodfinal method can be overloadedfinal method can not be override
11)abstract methodabstract method can be overloadedabstract method can be override

Example:

Method overloading Example:

method overloading example

Method overridding Example:

method overridding example

You may also like...

Leave a Reply