無論如何要把這個測試放在單獨的類中嗎?我嘗試過但沒有成功。在單獨的類中枚舉
public class TrafficLightprj
{
public enum TrafficLight
{
RED(1),
GREEN(2),
YELLOW(3);
private final int duration;
TrafficLight(int duration) {
this.duration = duration;
}
public int getDuration() {
return this.duration;
}
public static void main(String[] args)
{
for(TrafficLight light: TrafficLight.values())
{
System.out.println("The traffic light value is: " +light);
System.out.println("The duration of that trafic light value is: " + light.getDuration());
}
}
}
}
你是如何試圖將它們分開並失敗的?你可以在自己的類文件中有一個'enum'。 – birryree 2011-03-10 16:13:51