Enum Types An enum type is a type whose fields consist of a fixed set of constan
ID: 3565921 • Letter: E
Question
Enum Types An enum type is a type whose fields consist of a fixed set of constants. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week. Because they are constants, the names of an enum type's fields are in uppercase letters. In the Java programming language, you define an enum type by using the enum keyword. For example, you would specify a days-of-the-week enum type as: You should use gnum types any time you need to represent a fixed set of constants. That includes natural enum, types such as the planets in our solar system and data sets where you know all possible values at compile time-for example, the choices on a menu, command line flags, and so on. Here is some code that shows you how to use the Day enum defined above:Explanation / Answer
Output:
Mondays are bad.
Midweek days are so-so.
Fridays are better.
Weekends are best.
Weekends are best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.