Method overloading, also known as Function overloading or Compile time polymorphism, is a concept of having two or more methods with the same name but different signature in the same scope. There are many programming languages that support this feature: Ada, C++, C#, D, and Java.
Method overriding, also known as Function overriding or Run time polymorphism, is an OOP feature that allows a child class to provide its own implementation to the method defined in the parent class. The implementation in the child class overrides the definition of the method in the base class, provided that the method in the child class should have the same name, signature and return type.
Difference Between Method Overloading and Method Overriding
- In Method overloading methods must have a different signature. In method, overriding methods must have the same signature.
- Function Overloading is to “add” or “extend” more to method’s behaviour. Function overriding is to completely “change” or “redefine” the behaviour of a method.
- Method overloading is used to achieve Compile time polymorphism; method overriding is used to achieve run-time polymorphism.
- In method/function overloading compiler knows which object assigned to which class at the time of compilation, but in method overriding this information is not known till runtime.
- Function Overloading takes place in the same class whereas Overriding takes place in a class derived from a base class.