enum TrafficSignal {
//this will call enum constructor with one String argument
RED("wait"),
GREEN("go"),
ORANGE("slow down");
private String action;
public String getAction() {
return this.action;
}
// enum constructor - can not be public or protected
TrafficSignal(String action){
this.action = action;
System.out.println(this.action);
}
}
public class EnumConstructorExample{
public static void main(String args[]) {
// Only one Enum object initialized/instaniated
TrafficSignal c1 = TrafficSignal.GREEN;
}
}
Output:
wait
go
slow down
I am just wondering why the output would give the information of all the other Enum types despite the fact I only initialized one enum object (TrafficSignal.GREEN).