Answer» - Method overloading - Method Overloading is a polymorphism that occurs at COMPILE time. Method overloading is when a class has multiple methods with the same name but distinct signatures. The return type of a method can be the same or different in method overloading, but we must alter the argument SINCE we cannot create method overloading in Java by just changing the method's return type.
- Method overriding - Method Overriding is a polymorphism that occurs at RUNTIME. The derived class offers the exact implementation of the method that is already supplied by the base or parent class in method overriding. The return type must be the same or co-variant when overriding a method.
The following table lists the differences between method overloading and method overriding: | Method Overloading | Method Overriding |
|---|
| Method overloading is a polymorphism that occurs at compile time. | Method overriding is a polymorphism that occurs at runtime. | | It contributes to the program's readability. | It's used to provide the method's specific implementation, which is already provided by its parent or superclass. | | Method overloading is done within a single class. | Method overriding is done in two different CLASSES which have the relationship between them through inheritance. | | Inheritance may or may not be required for method overloading. | Inheritance is ALWAYS required for method overriding. | | Methods must have the same name but distinct signatures when overloading. | Methods that are overridden must have the same name and signature. |
|