public class ThisConstructorCall {
public ThisConstructorCall(String s) {
System.out.println("s = " + s);
} public ThisConstructorCall(int i) {
this("i = " + i);
} public static void main(String args[]) {
new ThisConstructorCall("Stringcall");
new ThisConstructorCall(47);
}
}运行结果为s = Stringcall
s = i = 47s=i=47是怎么来的

解决方案 »

  1.   

    this("i = " + i);
    相当于调用了:ThisConstructorCall(String s),所以就出来了
      

  2.   


    public class ThisConstructorCall {
    public ThisConstructorCall(String s) {//(2)step
    System.out.println("s = " + s);//(3)step, prints "s = Stringcall"
    }public ThisConstructorCall(int i) {//(5)step
    this("i = " + i);//(6)step, invoke another constructor,goto (2)step
    }public static void main(String args[]) {
    new ThisConstructorCall("Stringcall");//(1)step
    new ThisConstructorCall(47);//(4)step
    }
    }