Suppose i have two methods in a class say
public void eat(int i,String s)
and
public void eat(String s, int i)
then what is it like. Overloading or overriding?
Function overloading is used when we want multiple functions providing a similar implementation. However, function overriding is used when we want to add some additional functionality on top of base class implementation.
Performance: Overloading gives better performance compared to overriding. The reason is that the binding of overridden methods is being done at runtime. private and final methods can be overloaded but they cannot be overridden.
Method overloading is used to increase the readability of the program. Method overriding is used to provide the specific implementation of the method that is already provided by its super class.
In Java, method overriding occurs when a subclass (child class) has the same method as the parent class. In other words, method overriding occurs when a subclass provides a particular implementation of a method declared by one of its parent classes.
Overloading means two methods or more with the same name but with different parameters just like your example.While Overriding you implement a method from an interface or abstract class so the method in the super class has an implementation and in the subclass has a different one, Still they have the same method name and parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With