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

How to realize the inheritance of static methods in java Interface

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to realize the inheritance of static methods in the java interface". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize the inheritance of static methods in the java interface".

1. Format

Public static returns value type method name (parameter list) {}

2. Pay attention to use

Static methods can only be called through the interface name, not through the category name or object name.

Public can be omitted, but static cannot be omitted.

3. Examples

Because a class can implement multiple interfaces, inheritance conflicts occur if the methods of static methods in the interface are the same as before. Therefore, it interferes with the occurrence of conflicts from the level of inheritance. On the other hand, because the fields in the interface can be inherited, the fields in the interface actually have inheritance conflicts.

Interface TestInterface1 {String hello= "TestInterface1";} interface TestInterface1 {String hello= "TestInterface2";} public class Test implements TestInterface1,TestInterface2 {public static void main (String [] args) {System.out.println (Test.hello) / / an error will be reported here}} Thank you for your reading. The above is the content of "how to realize the inheritance of static methods in the java interface". After the study of this article, I believe you have a deeper understanding of how to achieve the inheritance of static methods in the java interface, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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