Wednesday, December 31, 2008

Enums

  • An enum specifies a list of constant values that can be assigned to a particular type.
  • An enum is NOT a String or an int; an enum constant's type is the enum type. For example, WINTER, SPRING, SUMMER, and FALL are of the enum type Season.
  • An enum can be declared outside or inside a class, but NOT in a method.An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.
  • Enums can contain constructors, methods, variables, and constant class bodies.
  • enum constants can send arguments to the enum constructor, using the syntax BIG(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.

0 comments: