What is Function Overloading and Overriding in OPPs?
Function Overloading and Overriding is the abilty of programming laguage to create multiple function with same name with different implementations
-Wikipedia
Function Overloading
Method or function overloading is generally used to increase the readability of the program. How? When we have a class with a bunch of functions and there are some functions having almost the same functionality or maybe a little different We create them using the same name but remember one thing they should accept different parameters. Method overloading is performed within the same Class.
- Method overloading is performed within a Class.
- Method overloading is an example of Compile-time Polymorphism
Method Overriding
Method overriding is used to provide the specific implementation of the method that is already provided by the superclass. How? When we create an instance of a class and we know that this class has the same properties and methods in the new instance class however if we want to overwrite a function in the newly instantiated class specifically, this is called Method Overriding. There is a condition that the Parameters should be same in the both Methods.
- Method overriding occurs in two classes that have IS-A (Instance) relationship
- In the case of Method Overriding, Parameters MUST be the same
- Method overriding is the example of RUN time Polymorphism
- The return type must be same or Co-variant in Method overriding
Comments & Questions (1 conversations)
Er Kumar Anup · 3 years ago
I know little what is overloading and overriding. By reading this awesome blogpost all doubts are cleared. Thank you sir for such a clearcut concepts.