内部类代码演示

 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 }

 

转载于:https://www.cnblogs.com/wdh1995/p/6719275.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值