首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

类变量初始化顺序哈哈哈

2012-10-07 
类变量初始化顺序哈哈我也不太清楚,先看代码吧;class X {private static X instance new X()int a 1

类变量初始化顺序哈哈
我也不太清楚,先看代码吧;

class X {private static X instance = new X();int a = 1;{System.out.println(a);}//static int b;static int b = 2;//2static {System.out.println(b);}private X() {super();a = 5;b = 6;}public static X getInstance(){return instance;}}public class Singleton{public static void main(String[] args) throws ClassNotFoundException {//Class.forName("com.mine.test.X");System.out.println("----------------");X x1 = X.getInstance();System.out.println(x1.a);System.out.println(X.b);}}


看了结果又点晕,
debug一下看了执行顺序,好了一点
有时间再深入研究下

热点排行