Enumeration classes: Classes that have a countable number of objects are called enumerated classes

1, custom enumeration class 2, using enum to achieve enumeration class 3, common methods in enum class 4, implementation interface enumeration class

Create an enum class by using the enum keyword

Format: enum Enum class name {}Copy the code

Note: 1. Enumeration classes defined with enum inherit from java.lang. enum by default and therefore cannot inherit from other classes

Constructors of enumerated classes can only use private permission modifiers

3, enumeration class declaration of the object must be first line, multiple objects separated by “,”,”,”;” Public static final is omitted by default

Enum Common methods

The value () method:

Returns an array of objects from an enumerated class. This method makes it easy to iterate through all the enumerated values

valueOf(String str):

Can convert a string into the corresponding enumeration class object, the request string must be enumerated class object “name”, if not, there will be a runtime exception: IllegalArgumentException