Java Reference
In-Depth Information
An enumerated value TrafficLight.red is assigned to variable light (line 3). Accessing
TrafficLight.RED causes the JVM to invoke the constructor with argument “please stop”.
The methods in enumerated type are invoked in the same way as the methods in a class.
light.getDescription() returns the description for the enumerated value (line 4).
Note
The Java syntax requires that the constructor for enumerated types be private to prevent
it from being invoked directly. The private modifier may be omitted. In this case, it is
considered private by default.
 
Search WWH ::




Custom Search