override of static method and final method

为君一笑 提交于 2019-12-30 11:18:08

问题


I know in Java, static method can not be overriden by the subclass.

Two questions:

1. Why is that? Could anyone explain me the reason inside it?

2. Can subclass override final method in super class then?


回答1:


Static methods aren't called on a particular instance - so they can't be called polymorphically. They are called on the type itself - nothing about the binding relies on any information which is only available at execution time. The point about polymorphic calls is that the method implementation which ends up being executed depends on the execution-time type of the target of the call; there's no target for static method calls, as such.

No, subclasses can't override final methods - the whole point of making a method final is to prevent it from being overridden.



来源:https://stackoverflow.com/questions/8547349/override-of-static-method-and-final-method

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