Method overload is polymorphism?

4

I'm having trouble understanding the concept of polymorphism in Java, I've read two articles from the same portal now, and got confused more, because for my interpretation they contradict each other:

Excerpt 1:

  

"Overload is a concept of polymorphism consisting basically of creating variations of the same method, that is, the creation of two or more methods with fully equal names in a class. the same name in more than one method as long as your argument lists are different for them to be separated. "

link

Excerpt 2:

  

"Polymorphism is the principle by which two or more classes derived from the same superclass can invoke methods that have the same identification, signature, but distinct, specialized behaviors for each derived class, using a reference to an object of the type the overload is not a type of polymorphism, because with overload the signature of the method must have different arguments, a requirement that hurts the concept of Polymorphism quoted above "    link

So, method overload is polymorphism too?

    
asked by anonymous 27.06.2018 / 03:40

1 answer

6

In general, publications, some even well-known ones can go wrong. In fact, everyone can. There's a lot of wrong stuff out there, often just because of some carelessness.

Note that in this case they are different articles from different authors, so it is normal for each one to have a view, here you will see other (s). Not always one is wrong just because it is different from another. Not in this case, but it is also good to always look at the date of publication. And the author's credentials, because paper and HTML accept everything.

  

Overload is a concept of polymorphism that consists basically in creating variations of the same method, that is, the creation of two or more methods with completely equal names in a class. Overloading allows us to use the same name in more than one method as long as your argument lists are different for them to be separated

It may be an ad-hoc polymorphism, but people do not usually use this term day by day.

The text is confusing and incomplete, but it is technically correct. The article as a whole is filled with strange and even clearly incorrect things in the details.

  

Polymorphism is the principle whereby two or more classes derived from the same superclass can invoke methods that have the same identification, signature, but distinct, specialized behaviors for each derived class, using a reference to an object of the type superclass. Overload is not a type of polymorphism, because with overload the signature of the method must have different arguments, a requirement that hurts the concept of Polymorphism quoted above

Why do you need two classes at least? Is not one just enough? It started badly already. usando para tanto uma referência a um objeto do tipo da superclasse seems confusing or just incorrect. I like this school more to consider overload as something different, although theoretically even it is, in practice we do not use that term.

It should cite where there is the requirement that the signature should be equal to be polymorphism. I have the impression that he can not, this has no basis. I say so because he is grounding. If it were just to cite, okay, if it's just to use different terms for each mechanism, it's fine to get easier to communicate intent.

The article has other things "loose".

  

In order to be polymorphic there has to be method overload, pus as wrong, so I got it right?

There are controversies. Classic overhead is horizontal, it's having methods with the same name, but with different signatures . There are those who call the vertical overload polymorphism where an identical method in the signature has different behavior depending on the level of the inheritance it is. But I prefer to call only polymorphism to avoid confusion. And it can occur dynamically, the most common, or static in general with templates or generics * .

I would not trust the articles.

    
27.06.2018 / 04:41