开发者

Can we override static method in Java? [duplicate]

开发者 https://www.devze.com 2023-01-05 04:38 出处:网络
This question already has answers here: 开发者_如何学编程 Closed 12 years ago. Possible Duplicates:
This question already has answers here: 开发者_如何学编程 Closed 12 years ago.

Possible Duplicates:

Why can’t static methods be abstract in Java

Static methods and their overriding

Why doesn’t Java allow overriding of static methods ?

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.

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.


No, but you can shadow it.

0

精彩评论

暂无评论...
验证码 换一张
取 消