标题:关键字this的问题!
取消只看楼主
ren829
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:15
帖 子:255
专家分:1174
注 册:2006-3-11
结帖率:100%
 问题点数:0 回复次数:1 
关键字this的问题!
public class Flower {
private int petalCount = 0;
private String s = new String("null");
Flower(int petals) {
petalCount = petals;
System.out.println(
"Constructor w/ int arg only, petalCount= "
+ petalCount);
}
Flower(String ss) {
System.out.println(
"Constructor w/ String arg only, s=" + ss);
s = ss;
}
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");
}
Flower() {
this("hi", 47);
System.out.println(
"default constructor (no args)");
}
void print() {
//! this(11); // Not inside non-constructor!
System.out.println(
"petalCount = " + petalCount + " s = "+ s);
}
public static void main(String[] args) {
Flower x = new Flower();
x.print();
}
}


这个程序的this到底是怎么工作的,还有我用x.Flower语句为什么不行啊!谢谢!
搜索更多相关主题的帖子: 关键 
2006-04-15 12:33
ren829
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:15
帖 子:255
专家分:1174
注 册:2006-3-11
得分:0 
谢谢楼上的两位的解释!

晓狐狸的解释很有意思!而且很容易让人理解,表示敬意!
2006-04-15 18:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-57636-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.163835 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved