public class TestConstructLoad { public static void main(String[] args) { new ConstructorLoad(1); } } class ConstructorLoad { //1.所有数据域被初始化为默认值(0,false,null) private int a; private String b = "xxxxxxxxx"; //2.按照在类中出现的次序,依次执行所有域初始化语句和初始化块 { System.out.println("初始化块a=" + a + ",b=" + b); a = 10; } //3.如果构造器第一行调用了第二个构造器,则执行第二个构造器主体 public ConstructorLoad() { System.out.println("ConstructorLoad无参数"); } //4.执行这个构造器的主体 public ConstructorLoad(int a) { this(); System.out.println("ConstructorLoad有参数,a=" + this.a + ",b=" + this.b); this.a = 20; } }
原文:http://my.oschina.net/OutOfMemory/blog/298956