public class InstanceInit {
/**
对象的构造和初始化过程
*/
// -1.静态变量默认初始化
public static int SInt;
// 2.默认初始化
public int iInt;
// ============ 静态块 ==========
static {
System.out.println("-1");
// 0.静态变量显式初始化
SInt = 10;
System.out.println("0");
}
// =========== 游离块 ===========
{
// 3.【显示初始化】
System.out.println("2");
this.iInt = 0;
System.out.println("3");
}
public InstanceInit(int iInt){
//System.out.println(this.iInt);
// 4.执行构造方法,对新构造对象的成员变量赋值
this.iInt = iInt;
System.out.println("4");
//System.out.println(this.iInt);
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("-----");
InstanceInit.SInt = 0;
// 1.系统为引用型变量分配引用空间(定长32位)
InstanceInit test;
System.out.println("1");
// 5.执行“=”,将新创建对象存储空间的首地址赋给变量 test
test = new InstanceInit(10);
System.out.println("5");
}
}