๐ชขSpecial Types
An enum is a special data type that defines a fixed set of constant values๐ {VALUE1, VALUE2, VALUE3}
To define an enum:
To use an enum:
Benefits:
๐ Defines a fixed set of values that is clear and understandable
๐ Limits variables to only those values, increasing program integrity
๐ฅ๏ธ Concise and readable code using human-friendly labels vs integers
๐ค Useful for representing defined, unchanging categories like statuses, states, options
Example
In this example, the Weekday enum defines the valid constant values. The main method shows variable declaration, conditionals, and attempted invalid assignment with enums.
Last updated