Welcome

Troves being gleaned while surfing on the Internet mostly about computer/IT/system skills and tricks, Welcome here ...
Powered By Blogger

Disclaimer

This blog is written by the owner with real practices and tests and intended to hold all original posts except there is a clear declaration for referencing from others. Thanks for tagging with the source link or other tips for reference from here if you would like to quote partial or full text from posts in this blog.

Friday, March 9, 2012

Overriding/overwriting and Overloading

It is often asked how overriding/overwriting differs from overloading and there are many posts online to answer related questions. Here I am summarizing the difference between them to give an overview as much complete as possible.

(1) Overloading provides multiple signatures for the same method in a single class, with the return value being not seen as part of the signature of method; Overriding provides a different implementation of a method inherited from a base type.

(2) Overloading is decided at compile time and overriding is decided at runtime, Overriding is basically the point of polymorphism by inheritance.

(3) Overloading lets you define a similar operation in different ways for different data, Overriding lets you define a similar operation in different ways for different object types.

(4) Using overloading and overridding, you can acheive the concept of polymorphism. Polymorphism means "one name, multiple forms". Using one name u can do multiple of actions. Method overloading is a compile time polymorphism and Method Overridding is a runtime polymorphism. Compile time polymorphism means compiler knows which object assigned to which class at the compiling time. Runtime polymorphism means compiler didn't know at the compile time, it only knows at a run time.

(5) Overriding method appears in subclasses, having the same name and same parameter list as a superclass method. The access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method.

=====================================

Similar to this topic, there is a differentiation between shadowing and overriding, found at