Is Method Overloading a Type of Polymorphism? [duplicate]

前提是你 提交于 2019-12-06 06:14:59

Sometimes, method overloading is indeed referred to as an example of "static polymorphism". This designation is somewhat arbitrary indeed, but it is possible to make a weak defense in its favor.

The concept of static polymorphism does exist, and it is not limited to OOP. Polymorphism (an ability to present the same behavior in different forms) can be static when polymorphic behavior is achieved based on compile-time type information. The most common example of such polymorphism is templates of C++: all calls are resolved statically, yet the behavior of a template is altered based on the static type of its type parameters.

Overloading could be thought of as a primitive form of choosing the behavior based on the static type of an object, too. However, this view of the overloading does not help understanding of the concept, and also makes it harder for the newcomers to understand the "real" (i.e. dynamic) polymorphism. That is why the term "static polymorphism" is not common in books on Java.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!