Java Reference
In-Depth Information
Notice that in the
case
statements, the names of the enumeration constants are used
without being qualified by their enumeration type name. That is,
TRUCK
, not
Trans-
port.TRUCK
, is used. This is because the type of the enumeration in the
switch
expression
has already implicitly specified the
enum
type of the
case
constants. There is no need to
qualify the constants in the
case
statements with their
enum
type name. In fact, attempting
to do so will cause a compilation error.
When an enumeration constant is displayed, such as in a
println( )
statement, its name
is output. For example, given this statement:
the name
BOAT
is displayed.
The following program puts together all of the pieces and demonstrates the
Transport
enumeration: