override of static method and final method

2019-02-19 21:34发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-02-19 22:08

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.

查看更多
登录 后发表回答