Flower(String s, int petals) {
this(petals);
//! this(s); // Can't call two!
this.s = s; // Another use of "this"
System.out.println("String & int args");
}这句话说明:
this当指代构造方法时( "this(...)" ),在一个构造方法中,只能使用一次,并且放在第一行否则编译出错 void print() {
//! this(11); // Not inside non-constructor!
System.out.println(
"petalCount = " + petalCount + " s = "+ s);
}这句话指出当this指代构造方法时( "this(...)" ),只能用于构造方法中,不能用于别的方法中Over
this(petals);
//! this(s); // Can't call two!
this.s = s; // Another use of "this"
System.out.println("String & int args");
}这句话说明:
this当指代构造方法时( "this(...)" ),在一个构造方法中,只能使用一次,并且放在第一行否则编译出错 void print() {
//! this(11); // Not inside non-constructor!
System.out.println(
"petalCount = " + petalCount + " s = "+ s);
}这句话指出当this指代构造方法时( "this(...)" ),只能用于构造方法中,不能用于别的方法中Over
{
private String flowerName;
private int petalCount; Flower()
{
this(null, 0);
} Flower(int petals)
{
this(null, petals);
} Flower(String name)
{
this(name, 0);
} Flower(String name, int petals)
{
flowerName = name == null ? new String(); name;
petalCount = petals > 0 ? petals : 0;
} public String toString()
{
return "Flower name is " + flowerName + " with " + petalCount + " petal(s).");
} void print()
{
System.out.println(this);
} public static void main(String[] args)
{
Flower x = new Flower();
x.print();
}
}
Flower x =ner Flower();
此时引用,当是具体如何我却搞不清,请大虾指教