Skip to Content
Java Quick Syntax Reference
book

Java Quick Syntax Reference

by Mikael Olsson
January 2018
Intermediate to advanced content levelIntermediate to advanced
115 pages
1h 37m
English
Apress
Content preview from Java Quick Syntax Reference
© Mikael Olsson 2018
Mikael OlssonJava Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3441-9_19

19. Enum

Mikael Olsson1 
(1)
Hammarland, Länsi-Suomi, Finland
 

An enumeration, or enum, 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 enum is the same as for a class. Package-private by default, but it can also be set to public if it’s declared in a file of the same name. As with classes, an enum 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 just shown can hold any one of the four ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Core Java 11 Advanced, Second Edition

Core Java 11 Advanced, Second Edition

Cay S. Horstmann
Java Illuminated, 4th Edition

Java Illuminated, 4th Edition

Julie Anderson, Hervé J. Franceschi

Publisher Resources

ISBN: 9781484234419Purchase LinkPublisher Website