What is enumeration, and the characteristics of enumeration

  1. Use the keyword enum to define an enumeration class

  2. All enumeration classes are subclasses of Enum

  3. The first line of the enumeration class must be an enumeration item. The semicolon after the last enumeration item can be omitted, but if the enumeration class has other things, this semicolon cannot be omitted. It is recommended not to omit.
    Each enumeration item is an object of the enumeration class!

  4. Each enumeration is a static constant, no other modifiers are allowed

  5. An enumeration class can have a constructor, but it must be private, and its default is also private.
    If it is an empty parameter construction, then the enumeration item can be omitted (), or parentheses
    can be added.
    If it is a parameter construction, then parameters can be added to the enumeration item (); if there is only one structure in the enumeration class Method, there are still parameters, then each enumeration item must be added () to pass the parameter

  6. Enumeration classes can have normal methods and can be invoked and executed
    by enumeration items

  7. Enumeration classes can also have abstract methods, but enumeration items must override this method

  8. Each class of the enumeration class inherits the Enum class by default, so it can no longer inherit other classes,
    but it can implement the interface, override its method, and call it with the enumeration item of the enumeration class

  9. Use of enumeration in switch statement

Guess you like

Origin blog.csdn.net/CV_Ming/article/details/111871804