Method Overriding & Overloading
December 7, 2022
Read Time: 1 mins 10 secs
Word Count: 275

In Object-Oriented Programming, methods are the operations associated with a
class. Methods are defined inside a class. Methods give an object of a class its behaviour. Sending a message to an object means calling or
invoking a method in the object. Methods are like functions in other programming paradigms.
What is Method Overloading
Overloading occurs in a class when there is more than one method with the same name but each has a different signature. The signature of a method is the name of the method and its parameter list including the data type, arity and order of the arguments but not the return type.If a class has several versions of a method Parent( ), for example void Parent( ), void Parent(int g), void Parent(float d, float h), then method Parent( ) is being overloaded. In Overloading the method name must be the same for overloading to be successful, the signature must be different, the return type can be overlooked, the data type of parameters, order of parameter and arity and body or contents of the method can be different.
Advantages of Method Overloading
- Method overloading enables methods to be accessed with a common name and a minimal disparity in the number or type of arguments while still performing closely comparable functions.
- They may also be applied to constructors, enabling several methods for initializing objects belonging to a class. A constructor is a particular that generates an instance of any class in objected oriented programming.
Disadvantages of Method Overloading
- If programmers desire to prevent having to rewrite a lot of code, they must put more effort toward developing the architecture beforehand.
Example

What is Method OverRiding
Overriding occurs when more than one method share the same name, same signature and same return type, in an inheritance hierarchy. Programmers must construct several separate method definitions in the class, each with the same name but a different list of parameters, in order to generate overloaded methods. If the parent class has a method called Login( ), and the child class also has a method called Login( ), then the child class method will override the parent class method. In Overriding the method name, signature, return type, data type of parameters, order of parameter and arity MUST be the same for overriding to be successful. The body or contents of the method can be different.
Example
