当前位置: 代码迷 >> Java相关 >> [求助]java代码中的this 都是什么意思?
  详细解决方案

[求助]java代码中的this 都是什么意思?

热度:79   发布时间:2007-10-19 12:23:25.0
[求助]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  代码  

----------------解决方案--------------------------------------------------------
this是指调用这个方法的当前对象
----------------解决方案--------------------------------------------------------

调用本类的构造器


----------------解决方案--------------------------------------------------------
  相关解决方案