Java学习之路(二)--Thinking in Java

针对昨天Java学习之路(一)--Thinking in Java中的类的静态方法不能访问创建非静态类,给出了将内部类修改成为static静态类,操作方便简单。现在给出第二种不需要添加删除的另一种极为高效的方式。可以将内部类从你所创建的类中复制粘贴到类外,作为一个外部类,在static主方法中就可以创建类的引用了。

       源代码如下:

class test{

  int s;

  char c;

}

public class test1 {

  public static class test{

    int s;

    char c;

  }

  public static void main(String[] args){

  test t = new test();

  System.out.println("s"+t.s);

  System.out.println("c"+t.c);

}

  

}

原文地址:https://www.cnblogs.com/zhaoyansheng/p/4824722.html