1. Format
public static返回值类型方法名(参数列表){ }
2. Usage Note
Static methods can only be called through the interface name, not through the category Called by name or object name.
Public can be omitted, static cannot be omitted.
3. Example
Since a class can implement multiple interfaces, if the static method in the interface has the same method as before, an inheritance conflict will occur. Thus, interfering with the occurrence of conflicts at the inheritance level. On the other hand, since the fields in the interface can be inherited, there is actually an inheritance conflict for the fields in the interface.
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);//这里会报错 } }
The above is the detailed content of How to inherit static methods in java interface. For more information, please follow other related articles on the PHP Chinese website!