- class OutClass
- {
- static class InnerClass
- {
- String s1 = "这是内部类的实例属性";
- InnerClass()
- {
- System.out.println("创建内部类对象!");
- }
- void innerTest()
- {
- System.out.println("这是内部类的test方法!");
- }
- }
- void accessInner()
- {
- System.out.println(new InnerClass().s1);
- }
- }
- class InnerClassAccess
- {
- public static void main(String[] args){
- OutClass oc = new OutClass();
- oc.new InnerClass().innerTest();
- }
- }
复制代码 |
|