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
解决方案 »
- 关于Swing中重启功能的实现,还请高手支招。
- 请高手们帮忙看一下,这段代码运行后,窗口的关闭按钮无效。
- 各位大虾.谁知道学习Thinking in java的技巧
- 又是一个基础问题,有劳了
- 自己做的,遇到问题特来请教!!!!!
- 最後10,請問怎麼得到一個文件(abc.doc)的最後修改日期 ,謝謝
- 关于DefaultTableModel的问题
- 如果通过流把文件和信息压缩成字节流并发送?
- java.util.Date 和 java.sql.Date有什么区别呀?
- 我看了论坛里所有的文章,还是没有明确的答案?!(20分)
- 求教:Java程序为何突然全部无法运行
- 哪位高手知道如何使用Servlet实现打印功能----高分回报
{
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();
此时引用,当是具体如何我却搞不清,请大虾指教