Enumerations included in JDK 5. An enumeration is a list of named constants. It is similar to final variables. • Enum in java is a data type that contains fixed set of constants. • An enumeration defines a class type in Java. By making enumerations into classes, so it can have constructors, methods, and instance variables. • An enumeration is created using the enum keyword. Ex: enum Apple { Jonathan, GoldenDel, RedDel, Winesap, Cortland } • The identifiers Jonathan, GoldenDel, and so on, are called enumeration constants. • Each is implicitly declared as a public, static final member of Apple. • Enumeration variable can be created like other primitive variable. It does not use the new for creating object. Ex:Apple ap; Ap is of type Apple, the only values that it can be assigned (or can contain) are those defined by the enumeration. For example, this assigns: ap = Apple.RedDel; implement code to given statement
Enumerations included in JDK 5. An enumeration is a list of named constants.
It is similar to final variables.
• Enum in java is a data type that contains fixed set of constants.
• An enumeration defines a class type in Java. By making enumerations into
classes, so it can have constructors, methods, and instance variables.
• An enumeration is created using the enum keyword.
Ex:
enum Apple { Jonathan, GoldenDel, RedDel, Winesap, Cortland }
• The identifiers Jonathan, GoldenDel, and so on, are called enumeration
constants.
• Each is implicitly declared as a public, static final member of Apple.
• Enumeration variable can be created like other primitive variable. It does not
use the new for creating object.
Ex:Apple ap;
Ap is of type Apple, the only values that it can be assigned (or can contain)
are those defined by the enumeration. For example, this assigns:
ap = Apple.RedDel;
implement code to given statement
Step by step
Solved in 2 steps with 2 images