Enumeration and Nested Classes

Cards (13)

  • An enumeration (enum) is a data type that contains a fixed set of constants.
  • Enums are good to use when you already know all possibilities of the values or instances of the class.
  • Enums can be declared on their own or within another class
  •  With numeric or String constants, you can pass an invalid value and not find out until runtime.
  • With enums, it is impossible to create an invalid enum value without introducing a compiler error.
  • creating an enum
  • The valueOf() method is used to convert the user’s input to an enumeration value. The program also retrieves the position of the selected period in the enumeration list.
  • ; type-safe is used to describe a data type for that allows only appropriate behaviors.
  • In Java, you can create a class within another class and store them together; such classes are called nested classes.
  • ·       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