I just read this line in book "Sun Certified Java Programmer" (page number-158) by Kathy Sierra and Bert Bates who worked as Master trainer at "Sun microsystems":
Polymorphism applies to overriding, not to overloading.
But some other books and articles say overloading is also a form of polymorphism.. i'm confused.. Please help..
Overriding is a form of polymorphism that is used in Java to dynamically bind the method from the subclass in response to a method call from a subclass object referenced by superclass type.
Overriding and overloading are the core concepts in Java programming. They are the ways to implement polymorphism in our Java programs. Polymorphism is one of the OOPS Concepts. Screenshot of Java code with arrows pointing at instances where overloading and overriding are occurring.
Polymorphism means more than one form, same object performing different operations according to the requirement. Method overloading means writing two or more methods in the same class by using the same method name, but the passing parameters are different.
No. 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.
Don't believe the other books. Late binding (wiki) (with overriden/inherited methods) is polymorphism. Static binding is what applies to overloading.
The two bolded expressions are concepts you should familiarize yourself with as soon as possible. There are a number of available resources. Maybe start here.
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