zoukankan      html  css  js  c++  java
  • 面向对象(静态内部类)

    /**
    * Created by rabbit on 2014-07-30.刘朋程.博客园
    * 内部类:将一个类定义在另一个类的里面,对里面的那个类
    * 就称为内部类(内置类,嵌套类)
    *
    * 当内部类在成员位置上,就可以被成员修饰符所修饰
    *
    * 比如 private;将内部类在外部类中进行封装。
    *      static:内部类就具备static特性
    *      当内部类被static修饰后,只能访问外部类的静态成员
    *      出现了访问局限。
    *
    *      在外部其他类中,如何直接访问static内部类的非静态成员呢?
    *      new outer2.inner2().function();
    *
    *      在外部其他类中,如何直接访问static内部类的非静态成员呢?
    *      outer2.inner2.function();
    */

    //Created by rabbit on 2014-07-30.刘朋程.博客园
    class outer2
    {
        private static int x = 3;
        static class inner2 //内部类
        {
            void function()
            {

                System.out.println("inner "+ x + "外部类静态变量"); //结果为3 内部类局部变量
            }
        }
    }
    //Created by rabbit on 2014-07-30.刘朋程.博客园
    public class innerclassDemo2 {
        public static void main(String [] args)
        {
            new outer2.inner2().function();
        }

    }
    //Created by rabbit on 2014-07-30.刘朋程.博客园

  • 相关阅读:
    Completely disable mousewheel on a WinForm
    C# Form内存回收
    解锁用户
    CentOS7+JDK8编译Hadoop2.6.4
    网址收藏
    pvresize
    Linux crontab 命令格式与详细例子
    在CentOS 7中安装与配置JDK8
    Disable SELinux CentOS 7
    Python3标准库:math数学函数
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/3890282.html
Copyright © 2011-2022 走看看