Published on June 16, 2022
Method overriding is a way to change or modify the behavior of a method that is already defined in a parent class. When we override a method, we provide a different implementation for that method in a child class. The child class has a method with the same name, return type, and parameters as the method in the parent class, but it performs a different action.
To override a method in Java, we follow these steps:
Example:
Method overloading is a way to have multiple methods with the same name in a class, but with different parameters. By overloading methods, we can perform similar operations with different types or numbers of inputs.
To overload a method in Java, we follow these steps:
Example:
The views expressed in this document are those of the author and do not necessarily reflect the position of the London School of Emerging Technology. View the detailed policy Disclaimer for Student and Personal Websites