Overridding and Overloading
Overridding and Overloading
Overriding occurs when a subclass provides a specific Overloading involves defining multiple methods
implementation of a method that is already defined in its in the same class with the same name but
Definition superclass. different parameters.
In overriding, the return type of the overridden method Overloading does not allow different return
can be covariant, meaning it can be a subtype of the types; methods must have the same return type
Return Type return type in the superclass method. or differ in parameters.
Overriding methods can have the same or less restrictive Overloaded methods can have different access
Access access modifiers compared to the overridden method in modifiers, as long as they are not less restrictive
Modifiers the superclass. than the original method.
Overriding methods can throw the same exceptions or a Overloaded methods can throw any exceptions,
subset of the exceptions thrown by the superclass but they cannot have a different throws clause
Exception method, or they can throw no exceptions (a narrower or compared to other overloaded methods with
Handling no exception specification). the same name.