//静态代码块内部类
public class test18{private static final String URL;private static final String DEVICE;private static final String USER;private static final String ROOT;static test18 self;static {class Inner{public void printMessage(){System.out.println("我是定义再static里的内部类");}}URL="歌谣";DEVICE="笔记本电脑";USER="root";ROOT="歌谣";if(self==null){newTest18();Inner inner=new Inner();inner.printMessage();}}private test18(){}public static String getURL() {return URL;}public static String getDEVICE() {return DEVICE;}public static String getUSER() {return USER;}public static String getROOT() {return ROOT;}private static void newTest18(){self=new test18();}}
定义一个测试类
public class test19 {public static void main(String[] args){System.out.println(test18.getDEVICE());System.out.println(test18.getURL());}
}
运行结果