运行了一下,输出的结果是:Constructor w/ int arg only, petalCount= 47
String & int args
default constructor (no args)
petalCount = 47 s = hi原因:
Flower x = new Flower(); 调用Flower()构造方法在Flower()构造方法中,this("hi", 47);调用 Flower(String s, int petals) 构造方法Flower(String s, int petals) 构造方法中,this(petals);调用Flower(String ss) 构造方法Flower(String ss) 构造方法中,没有再调用其他的构造方法,执行其中的代码
所以打印出第一句:Constructor w/ int arg only, petalCount= 47然后执行完Flower(String ss) 构造方法中的内容,再执行Flower(String s, int petals) 构造方法中的内容,所以打印出第二句:String & int args然后执行完Flower(String s, int petals) 构造方法中的内容,再执行 Flower()构造方法中的内容,所以打印出第三句:default constructor (no args)所有的构造方法都执行完后,执行 x.print();打印出第四句:petalCount = 47 s = hi