Chinaunix首页 | 论坛 | 博客
  • 博客访问: 605614
  • 博文数量: 796
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 5095
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-10 09:43
文章分类

全部博文(796)

文章存档

2011年(1)

2008年(795)

我的朋友

分类:

2008-09-10 10:06:35

public class  Outer{
    
//just like static method, static member class has public/private/default access privilege levels
    
    
//access privilege level: public 
    public static class Inner1 {
        
public Inner1() {
            
//Static member inner class can access static method of outer class
            staticMethod();    
            
//Compile error: static member inner class can not access instance method of outer class
            
//instanceMethod();  
        }
    }
    
    
//access privilege level: default 
    static class Inner2 {
        
    }
    
    
//access privilege level: private 
    private static class Inner3 {
        
//define a nested inner class in another inner class 
        public static class Inner4 {    
        }
    }

    
private static void staticMethod() {
        
//cannot define an inner class in a method
        /*public static class Inner4() {
        }
*/
    }
    
    
private void instanceMethod() {
        
//private static member class can be accessed only in its outer class definition scope
        Inner3 inner3 = new Inner3();
        
//how to use nested inner class
        Inner3.Inner4 inner4 = new Inner3.Inner4();
    }
}

class Test {
    Outer.Inner1 inner1 
= new Outer.Inner1();
    
//Test and Outer are in the same package, so Inner2 can be accessed here
    Outer.Inner2 inner2 = new Outer.Inner2(); 
    
//Compile error: Inner3 cannot be accessed here
    
//Outer.Inner3 inner3 = new Outer.Inner3(); 
}
--------------------next---------------------

阅读(300) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~