标题:[求助]java代码中的this 都是什么意思?
只看楼主
sishui198
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2007-4-12
 问题点数:0 回复次数:2 
[求助]java代码中的this 都是什么意思?

//: Flower.java
// Calling constructors with "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 都是什么意思?写具体一点,谢谢!

搜索更多相关主题的帖子: java 代码 
2007-10-19 12:23
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
得分:0 
this是指调用这个方法的当前对象

I'm here, as always...
2007-10-19 12:42
狂放不羁
Rank: 4
等 级:贵宾
威 望:12
帖 子:925
专家分:0
注 册:2007-1-24
得分:0 

调用本类的构造器

2007-10-19 13:00



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




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

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