Java enum : enum « Object Oriented « SCJP






An enum specifies a list of constant values assigned to a type.

An enum is NOT a String or an int. 

An enum constant's type is the enum type. 

An enum can be declared outside or inside a class, but NOT in a method.

You can NEVER invoke an enum constructor directly. 
The enum constructor is invoked automatically, with the arguments you define after the constant value. 

You can define more than one argument to the constructor, and you can overload the enum constructors

An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.

enum constants can send arguments to the enum constructor, using the syntax BIG(8).

Compiling an enum generates a .class file whose name is derived from the enum's name.

The semicolon at the end of an enum declaration is optional. These are legal:

enum Foo { ONE, TWO, THREE}
enum Foo { ONE, TWO, THREE};

Foo.values() returns an array of MyEnum's values.








6.11.enum
6.11.1.Java enum
6.11.2.Declaring Enums
6.11.3.An example of declaring an enum inside a class
6.11.4.You cannot declare enums in a method
6.11.5.It is optional to put a semicolon at the end of the enum declaration
6.11.6.Declaring Constructors, Methods, and Variables in an enum
6.11.7.Enums are subclasses of java.lang.Enum.
6.11.8.You can declare an enum anywhere you can declare a class.
6.11.9.Enums inherit data and methods from Object.
6.11.10.Enums may be converted and cast according to the same rules that govern any class that extends Object.
6.11.11.Enums may have main() methods and can be invoked as applications.
6.11.12.Enums that have no explicit constructors get default no-args constructors.
6.11.13.Enums have built-in name() and toString() methods, both of which return the name of the current instance.
6.11.14.You can add data, methods, and constructors to an enum.