What are the defining rules of Java enums?
The rules for defining Java enum are as follows:
- Define an enumeration type using the keyword enum.
- Constants must be listed on the first line of the enumeration type, separated by commas, and end with a semicolon.
- Constants are typically written in uppercase letters, and if they consist of multiple words, they are usually separated by underscores.
- Enumeration types can have constructors, methods, and fields.
- The enum constants inside an enum type are singletons.
- Enum types can also implement interfaces, and each enum constant needs to implement the abstract methods in the interface.