I have a long standing doubt. Could someone please tell me whether method overloading is a form of polymorphism or is it something completely different?
Method overloading is just a syntax sugar allowing you to have methods with same name but different arguments. It has nothing to do with polymorphism. Method overloading is typically used to define two methods accepting different arguments, e.g.:
public void println(boolean x) //...
public void println(char x) //...
or to skip certain parameters and use some defaults:
public String substring(int beginIndex) //...
public String substring(int beginIndex, int endIndex) //...
Method overriding, on the other hand, is a foundation of inheritance and is more closely related to polymorphism.
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