public class E10_ThisConstructorCall {
public E10_ThisConstructorCall(String s) {
System.out.println("s = " + s);
}
public E10_ThisConstructorCall(int i) {
this("i="+i);
}
public static void main(String args[]) {
new E10_ThisConstructorCall("String call");
new E10_ThisConstructorCall(47);
}
}是不是 this("i="+i)中的i会由int转换成string类型?为什么 this("i="+i)的结果 ; 会等于 s= i = 47 呢?
public E10_ThisConstructorCall(String s) {
System.out.println("s = " + s);
}
public E10_ThisConstructorCall(int i) {
this("i="+i);
}
public static void main(String args[]) {
new E10_ThisConstructorCall("String call");
new E10_ThisConstructorCall(47);
}
}是不是 this("i="+i)中的i会由int转换成string类型?为什么 this("i="+i)的结果 ; 会等于 s= i = 47 呢?
s=String call
s=i=47
i thdd df ;lsdkfj;sdkjf
public E10_ThisConstructorCall("i=47")所以就得到的最后的结果 了
this("s"+i);
的确是先把它转换成字符串了,因为在java语言里,字符串的"+"运算符都是把它们转换成字符串,相当于一个连接,你用对象试试,会是null.呵呵...
所以再次调用上一层的构造函数所以结果就是这样罗....