Enumeration and Nested Class Flashcards
Enumeration
A data type that contains a fixed set of constants
Using an enum
Period p;
p = Period.{enum data}
ordinal()
Returns an integers that represent constant’s position in the list of contants.
you can pass an invalid value and not find
out until runtime
numeric or String constants
With enums
it is impossible to create an invalid enum value
without introducing a compiler error
toString()
Returns the name of the calling constant object
static member class
has access to all static methods of the top-
level class
Non-static member class (inner class
requires an instance; it has
access to all data and methods of the top-level class.
Local class
defined within a method body Anonymous class – a special case of a local class that has not identifier
valueOf()
Accepts a string parameter and returns an enumeration constant
values()
Returns an array of the enumerated constants
equals()
Returns true if its argument is
equal to the calling object’s
value
compareTo()
the calling object’s ordinal value is less than that of the argument, 0 if they are the
same, and a positive integer if
the calling object’s ordinal value
is greater than that of the
argument