//: initialization/Flower.java
// Calling constructors with "this"
import static net.mindview.util.Print.*;
public class Flower {
int petalCount = 0;
String s = "initial value";
Flower(int petals) {
petalCount = petals;
print("Constructor w/ int arg only, petalCount= "
+ petalCount);
}
Flower(String ss) {
print("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"
print("String & int args");
}
Flower() {
this("hi", 47);
print("default constructor (no args)");
}
void printPetalCount() {
//! this(11); // Not inside non-constructor!
print("petalCount = " + petalCount + " s = "+ s);
}
public static void main(String[] args) {
Flower x = new Flower();
x.printPetalCount();
}
} /* Output:
Constructor w/ int arg only, petalCount= 47
String & int args
default constructor (no args)
petalCount = 47 s = hi
*///:~
问题:C:\Users\lenovo\Desktop\TIJ4-code\initialization>javac Flower
Flower.java:3: 错误: 程序包net.mindview不存在
import static net.mindview.util.Print;
^
Flower.java:3: 错误: 仅从类和接口静态导入
import static net.mindview.util.Print;
^
Flower.java:10: 错误: 找不到符号
print("Constructor w/ int arg only, petalCount= "
^
符号: 方法 print(String)
位置: 类 Flower
Flower.java:14: 错误: 找不到符号
print("Constructor w/ String arg only, s = " + ss);
^
符号: 方法 print(String)
位置: 类 Flower
Flower.java:21: 错误: 找不到符号
print("String & int args");
^
符号: 方法 print(String)
位置: 类 Flower
Flower.java:25: 错误: 找不到符号
print("default constructor (no args)");
^
符号: 方法 print(String)
位置: 类 Flower
Flower.java:29: 错误: 找不到符号
print("petalCount = " + petalCount + " s = "+ s);
^
符号: 方法 print(String)
位置: 类 Flower
7 个错误
我用的是editplus 编辑的,在DOS里运行的,能否通过把net.mindview.util进行classpath环境变量设置来解决这个问题?