标题: 跟静态有关的初始化 [打印本页] 作者: ☆今☆ 时间: 2013-7-28 21:11 标题: 跟静态有关的初始化 关于静态的初始化题
public class StaticDemo {
public static void main(String[] args) {
Demo1 d = Demo1.getInstance();
System.out.println(d.count1+"......."+d.count2);
}
}
class Demo1{
private Demo1(){
System.out.println(count1+"...构造函数前..."+count2);
count1++;
count2++;
System.out.println(count1+"...构造函数后..."+count2);
}
public static int count1;
public static int count2=2;
static{
System.out.println(count1+"...静态代码块前..."+count2);
count1++;
count2++;
System.out.println(count1+"...静态代码块后..."+count2);
}
private static Demo1 d = new Demo1();