![java enum java enum](https://linuxhint.com/wp-content/uploads/2022/03/word-image-369.png)
The enhanced switch only allows the name of a constant as a case label, without enum type prefix. When using enum in switch statement, the enum constants are the only allowed labels for cases. Enums are supported by the switch statement from java 5.We can use = to compare enum constants effectively because constants are final and we cannot call an enum’s constuctors to create more constants.When anything else other than constants are there, comma separated constants should be terminated with a semicolon.Anonymous class is created using curly braces after the constructor or directly after constant name in case of no-parameterized constructor. We can enhance an enum to assign a different behavior to each constant by introducing an abstract method into the enum and overriding this method in an anonymous subclass of the constant.Compiler won’t allow us to explicitly extend the Enum class.
JAVA ENUM CODE
We then used these constants within the code for comparisons and all like if(weekDay = Weekday.SUNDAY) into a class with name Weekend and extends Enum.
![java enum java enum](https://i2.wp.com/springframework.guru/wp-content/uploads/2018/04/enumIterationTest.png)
Before enums we had to create an enumerated type by enclosing many final static int/String variables inside a class as below. In the Java programming language, you define an enum type by using the enum keyword. In plain English, "to enumerate" means to count off or name one by one from a list. Eg: Months in a calendar or days in a week. An enum type (or enumerated type) is a type whose fields consist of a fixed set of constants.