Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Can static properties and static methods in java be inherited?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article to share with you is about static properties and static methods in java can be inherited, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

Conclusion:

Static properties and static methods in Java can be inherited, but they are not overwritten, but hidden.

Cause analysis:

1. Static methods and attributes belong to classes, and can be called directly through class names. Method name is complete and can be invoked without inheritance mechanisms.

If static methods and attributes are defined in the subclass, then the static methods or attributes of the parent class are called "hidden." If you want to call static methods and properties of a parent class, go directly through the parent class name. Method or variable name completion, as for whether to inherit one, subclass is inherited static methods and attributes, but with instance methods and attributes are not the same, there is "hidden" this situation.

(Online learning video tutorial sharing: java video tutorial)

The reason why polymorphism can be realized depends on inheritance, interface and rewriting, overloading (inheritance and rewriting are the most critical). With inheritance and overriding, references to parent classes point to objects of different child classes.

The function of rewriting is that after "rewriting", the child class has higher priority than the parent class, but "hiding" does not have this priority.

Static attributes, static methods and non-static attributes can be inherited and hidden and cannot be overridden, so polymorphism cannot be achieved, and references to parent classes can point to objects of different subclasses. Non-static methods can be inherited and overridden, so polymorphism can be achieved.

The above is the static properties and static methods in java can be inherited, Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report