面向对象(局部内部类和匿名内部类)

/**
* Created by rabbit on 2014-08-05.
* 内部类定义在局部时,
* 1、不可以被成员修饰符修饰
* 2、可以直接访问外部类中的成员,因为还持有
* 外部类中的引用。但是不可以访问他所在的局部中
* 的变量。只能访问被final修饰的局部变量。
*
* 匿名内部类
* 1、匿名内部类就是内部类的简写格式
* */
class outer4
{
    int x = 3 ;
    void method()
    {
        final int y = 5;
        class inner
        {
            void function()
            {
                System.out.println(y);
            }
        }
        new inner().function();
    }

}
public class innerclassDemo4 {
    public static void main(String [] args)
    {
        new outer4().method();
    }
}

posted @ 2014-08-05 12:11  liupengcheng  阅读(350)  评论(0编辑  收藏  举报