接口
Java的接口可以包含方法签名、常量和嵌套类,见下例:
1 public final class Program {
2 public static void main(String[] args) {
3 Playable.EMPTY.play();
4
5 new Dog().play();
6 }
7 }
8
9 interface Playable {
10 Playable EMPTY = new EmptyPlayable();
11
12 void play();
13
14 class EmptyPlayable implements Playable {
15
16 @Override
17 public void play() {
18 System.out.println("无所事事");
19 }
20
21 }
22 }
23
24 class Dog implements Playable {
25
26 @Override
27 public void play() {
28 System.out.println("啃骨头");
29 }
30
31 }
https://www.bilibili.com/video/BV1qL411u7eE?spm_id_from=333.337.search-card.all.click
1549

被折叠的 条评论
为什么被折叠?



