我们可以覆盖Java中的静态方法吗? [英] Can we override static method in Java?
本文介绍了我们可以覆盖Java中的静态方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以覆盖Java中的静态方法吗?
Can we override static method in Java?
推荐答案
否。静态方法与它们定义的类相关联。它们是通过类调用的,而不是通过对象调用的,并且没有动态调度可能发生重写。
No. Static methods are tied to the class they're defined in. They're invoked through the class, not through an object, and there is no dynamic dispatch where overriding could happen.
您可能感到困惑,因为Java允许您通过对象引用调用静态方法。这通常被认为是设计错误,并且它不像调用实例方法那样工作,因为引用的编译时类型决定调用哪个方法。
You're probably confused because Java allows you to invoke static methods through an object reference. That's generally considered a design error, and it does not work like invoking instance methods, because the compile-time type of the reference decides which method gets invoked.
这篇关于我们可以覆盖Java中的静态方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文