内部类代码演示

 1 package com.wisezone.inner;
 2 /**
 3  * 内部类
 4  * 使用内部类的前提是你必须要先创建一个外部类
 5  * @author 王东海
 6  * @2017年4月16日
 7  */
 8 public class Other
 9 {
10     //静态属性方式来使用
11     class Inner{
12         
13     }
14     
15     //局部变量的方式来使用
16     static class Inner02{
17         
18     }
19     
20     //在方法里
21     //相当于成员变量
22     public void test(){
23         final int a = 3;
24         class Inner03{
25             public void test02(){
26                 System.out.println("Other.test().Inner03.test02()"+a);
27             }
28         }
29         Inner03 inner03 = new Inner03();
30         inner03.test02();
31         
32     }
33     
34     
35     public static void main(String[] args)
36     {
37         //外部类
38         Other other = new Other();
39         
40         //外部类.内部类
41         Other.Inner inner = other.new Inner(); 
42         
43         //静态内部类创建方式调用
44         Other.Inner02 inner02 = new Other.Inner02();
45     }
46 }

 

posted @ 2017-04-16 17:11  程序员的世界。。。  阅读(148)  评论(0编辑  收藏  举报