Tuesday, April 21, 2015

Java Enumeration

The Java programming language contains the enum keyword, which represents a special data type that enables for a variable to belong to a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. The values defined inside an enum are constants and shall be typed in uppercase letters. Also, these values are implicitly static and final and cannot be changed, after their declaration. If an enum is a member of a class, then it is implicitly defined as static. Finally, you should use an enum, when you need to define and represent a fixed set of constants.

public enum Day {
 SUNDAY,
 MONDAY,
 TUESDAY,
 WEDNESDAY,
 THURSDAY,
 FRIDAY,
 SATURDAY
}

No comments:

Post a Comment