String model;
int year;
enum Color {GREEN, BLUE, RED};
double price;
顏色色調;將ENUM類型指定給構造函數
public Car(String model, int year, Color shade, double price) {
this.model = model;
this.year = year;
this.shade= shade;
this.price = price;
}
可以這樣做嗎?當我用主要方法實際製作對象時仍然出現錯誤。
不,你沒有。這不知道枚舉的工作。你已經聲明瞭一個類型,你沒有定義一個實例。 – Ivan
嘿,那我該怎麼做? –