菜鸟学java百问(1)
各位高手:
小弟刚学java不久,在书上有如下一段程序:
package lee;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class Flower{
private int petalCount=0;
private String s = new String ("null");
Flower (int petals) {
petalCount = petals;
System.out.println(
"Coustructor 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=s;
System.out.println("String & int args");
}
Flower() {
this("hi",47);
System.out.println(
"deault counstructor (no args)");
}
void print() {
System.out.println(
"petalCount=" + petalCount + "s=" + s);
}
public static void main(Sting[] args) {
Flower x=new Flower();
x.print();
我用jbuilder6 run project 结果出了一下错误
"Untitled1.java": Error #: 475 : class Flower is public; must be declared in a file named Flower.java at line 12, column 8
"Untitled1.java": Error #: 300 : class Sting not found in class lee.Flower at line 40, column 27
这个程序是为了说明 this 关键字的构建器中调用构建器 内容
但是,对于这个问题我还不很清楚, 希望对此能为我详细说明一下。
1 哪里体现构建器调用??
2 怎么运行不了程序????
3 关于 this 关键字 除了这里说的,还有什么相关重要知识??
希望对于这个问题能给小弟一个全面详细的解说!!