CHAPTER 19

image

Enum

An enumeration is a type that consists of a fixed list of named constants. To create one, the enum keyword is used followed by a name and a code block, containing a comma separated list of constant elements. The access level for an enumeration is the same as for a class. Package-private by default, but it can also be set to public if it is declared in a file of the same name. Just as with classes, an enumeration can be contained within a class, where it can then be set to any access level.

enum Speed{   STOP, SLOW, NORMAL, FAST}  

An object of the enum type above can hold any one of the four defined constants. The enum constants ...

Get Java Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.