Java中的内部类、匿名类的使用

代码(test.java):

 1 interface ie{
 2     public void print();
 3 }
 4 
 5 class outer{}
 6 
 7 public class test{
 8     public class inner{}
 9     public void test(ie e){
10         e.print();
11     }
12     public static void main(String[] args){
13 
14 
15         new test().test(new ie(){
16             public void print(){
17                 System.out.println("匿名类");
18             }
19         });
20 
21     }
22 }

编译后产生class文件包括:

接口ie.class  
外部类outer.class  
内部类test$inner.class
匿名类test$1.class  
test.class  

 输出:

匿名类

 

posted @ 2016-06-15 22:05  hu983  阅读(143)  评论(0编辑  收藏  举报