1 package face_09;
2
3 import sun.jvm.hotspot.ui.action.ShowAction;
4
5 interface Inter{
6 void show1();
7 void shwo2();
8 }
9 /*
10 * 通常的使用场景之一:
11 * 当函数参数是接口类型时,而且接口中的方法不超过三个。(方法太多阅读性不好)
12 * 可以用匿名内部类作为实际参数进行传递。
13 */
14
15 class Outer{
16 /*
17 class Inner implements Inter {
18 public void show1() {
19
20 }
21 public void show2() {
22
23 }
24 }
25 */
26 public void method() {
27 Inter in = new Inter() {
28 public void show1() {
29
30 }
31 public void show2() {
32
33 }
34 };
35 in.show1();
36 in.shwo2();
37 /* new Inter() {
38 public void show1() {
39
40 }
41 public void show2() {
42
43 }
44 }.show2();
45 */
46 }
47
48 }
49 public class InnerClassDemo5 {
50 public static void main(String[] args) {
51 System.out.println("Hello World!");
52 show(new Inter() {
53 public void show1() {}
54 public void show2() {}
55 });
56 }
57 public static void show(Inter in) {
58 in.show1();
59 in.shwo2();
60 }
61 }