- 整体思路:
step1:类加载过程
step:执行main方法里的代码 - 细节:
new 执行完 —— 执行构造块 ——执行构造方法
public class Text{
public static int k = 0;
public static Text t1 = new Text("t1");
public static Text t2 = new Text("t2");
public static int i = print("i");
public static int n = 99;
public int j = print("j");
{
print("构造块");
}
static{
print("静态块");
}
public Text(String str){
System.out.println((++k)+":"+str+" i="+i+" n="+n);
++i;
++n;
}
public static int print(String str){
System.out.println((++k)+":"+str+" i="+i+" n="+n);
++n;
return ++i;
}
public static void main(String args[]){
new Text("init");
}
}