为什么我们不能重写非静态方法以使其静态。我在尝试执行此操作时遇到此错误:
This static method cannot hide the instance method from aSuperClass.
非常感谢!
最佳答案
重写意味着在子类中为实例方法提供新的实现,实例方法可能会或可能不会与类实例成员一起使用。覆盖它们并将它们重新定义为静态是不合逻辑的。 static
表示方法与类相关,而不是与类的实例相关。
在 C# 和 Java 中都无法做到这一点。
对于 C#,请查看 override - MSDN
You cannot use the new, static, or virtual modifiers to modify an override method.
关于Java:为什么我们不能重写一个方法使其成为静态的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16292667/