| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 499 人关注过本帖
标题:关键字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
快速回复:关键字this的问题!
数据加载中...
 
   



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

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