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.刘朋程.博客园

  • 相关阅读:
    PHP之目录遍历
    PHP之验证码
    PHP之验证码
    PHP之异常处理模式
    PHP之pdo的预处理模式
    PHP之PDO
    PHP之cookie和session
    PHP之MVC
    单例模式
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/3890282.html
Copyright © 2011-2022 走看看