Java — Runtime typing differences

跟風遠走 提交于 2019-12-05 09:42:26
Mike Samuel

In the first example, a method signature is chosen at compile-time from among a number of overloaded signatures. The Java language specification says that this is done based on the static type of the variables.

In the second example, an implementation of a given method signature is chosen at runtime based on virtual method dispatch. This is done based on the runtime type of the class containing the method definition.

Situation #1 is method overloading, which is static at compile time. Situation #2 is polymorphism, which is dynamic at runtime.

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