Java Enum 5 Min Drill

  • enum specifies a list of constant values assigned to a type.
  • enum is NOT a String or an int; an enum constant's type is the enum type. e.g. CIRCLE and SQUARE are of the enum type Shape.
  • enum can be declared outside or inside a class, but NOT in a method.
  • enum declared outside a class must NOT be marked static, final, abstract, protected, private.
  • enums can contain constructors, methods, variables, and constant-specific class bodies.
  • enum constants can send arguments to the enum constructor, using the syntax CIRCLE(8), where the int literal 8 is passed to the enum constructor.
  • enum constructors can have arguments and can be overloaded.
  • enum constructors can NEVER be invoked directly in code. They are always called automatically when an enum is initialized.
  • The semicolon at the end of an enum declaration is optional. These are legal:
    enum MyNum { ONE, TWO, THREE}
  • MyEnum.values() returns an array of MyEnum's values.
  • enum have only private constructor.