<分区>
我的 jail 是使用一个类的实例作为另一个类的参数。我将用一个例子来描述我的问题。
public class Color {
public String color;
public Color (String color) {
this.color = color;
}
public Color grey = new Color("grey");
}
我的目标是构建另一个使用我的第一个类的实例作为参数的构造函数(例如汽车):
public class car {
int PS;
Color color;
public Auto (int PS, Color color) {
this.PS = PS;
this.color = color;
}
public static void main (String args[]) {
car myCar = new car(80, grey);
}
我收到错误“Java 找不到符号”。我尝试了很多但无法让它运行,而且我没有完全理解我猜的类的概念。