java接口的静态方法使用

java接口的静态方法使用

注意事项:

不能通过接口实现类的对象来调用接口当中的静态方法。

正确用法:

通过接口名称,直接调用其中的静态方法。

格式:

接口名称.静态方法名(参数);

1
2
3
4
package cn.itcast.day10.demo01;

public class MyInterfaceStaticImpl implements MyInterfaceStatic {
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package cn.itcast.day10.demo01;


public class Demo03Interface {

public static void main(String[] args) {
// 创建了实现类对象
MyInterfaceStaticImpl impl = new MyInterfaceStaticImpl();

// 错误写法!
// impl.methodStatic();

// 直接通过接口名称调用静态方法
MyInterfaceStatic.methodStatic();
}

}