Java Keyword Enum

The reserved keyword enum is used to declare a new enumeration type that enables a variable to be a set of predefined constants. Take a look at the enum data type sample code.

Let’s first take a look at the syntax to define an enum type.

//JavaCodeDepot Sample 

enum <name> {
     [ENUM_CONSTANT_1],
     [ENUM_CONSTANT_2],
     [ENUM_CONSTANT_3],
     [ENUM_CONSTANT_4],
     [ENUM_CONSTANT_5],
}


The sample code below will define a new enum data type inside a Java class.

//JavaCodeDepot.com Sample

class JavaCodeDepotClass {
    enum Weekdays {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};
}


The complete list of Java reserved keywords contains a total of 50 keywords and 3 literal words that are unable to be used as variable names.

Add a Comment

Your email address will not be published. Required fields are marked *