Do not start too technical first, try to make sense. The meaning of polymorphism in OOP is the ability of an object to behave differently. now let's think about how method overloading is polymorphism
Method overloading is polymorphism
The OOP method shows the behavior using the method overload method in java, you can create a method with the same name but with a different list of parameters, now you can start thinking .. the same name means β the same behavior, but we know, although the name is similar the behavior is not quite the same .. in simple polymorphic words
Example
: you have an βeatβ method in the human class, now you are creating another reception method with a different list of parameters, according to which method you call expected behavior changes.
Method overriding is polymorphism
then how is method overriding a polymorphism? try to understand this. in the override method, you override the method that is defined in the superclass.
ex: the person has a food method, and now you create the SuperHuman class, which is a subclass of the person and then overrides the nutrition method
therefore, we know that SuperHuman also has the ability to eat, but in a different way, but not like overloading here now, we have the problem of demonstrating polymorphism. Why, because if you create an instance of a person, then there is one method, so polymorphic behavior does not exist. just as if you created an instance of SuperHuman, then there is one method and one expected behavior so that there is no polymorphism. therefore we demonstrate
Human a = new Human(); a.eat(); Human b = new SuperHuman(); b.eat();
we canβt just say what method does the output, looking only at the left side, because both βaβ and βbβ are a type of person, so the compiler cannot be sure what the output of a.eat () will be and b.eat () until the code runs, so that it is polymorphic.