构造函数如何调用
public class study {
private String s = new String("null");
private int petalCount = 0;
study(String ss) {
System.out.println(
"------------------------");
}
study(String s, int petals) {
this(petals);
//! this(s); // Can't call two!
this.s = s; // Another use of "this"
System.out.println("222222222222222222222---"+s);
}
study(int petals) {
petalCount = petals;
System.out.println(
"1111111111111111111111---"
+ petalCount);
}
study() {
this("hi", 47);
System.out.println(
"333333333333333333333333");
}
void print() {
//! this(11); // Not inside non-constructor!
System.out.println(
"petalCount = " + petalCount + " s = "+ s);
}
public static void main(String[] args)
{
study x = new study();
x.print();
}
为什么运行结果是:
1111111111111111111111---47
222222222222222222222---hi
333333333333333333333333
petalCount = 47 s = hi
这个构造为什么没有执行:study(String ss)