zoukankan      html  css  js  c++  java
  • 面向对象(局部内部类和匿名内部类)

    /**
    * 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();
        }
    }

  • 相关阅读:
    栈和队列
    链表
    map
    二叉平衡树旋转
    二叉排序树详情
    红黑树详情
    查并集
    动态规划
    位操作
    字典树
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/3891995.html
Copyright © 2011-2022 走看看