WHAT ARE ENUMERATIONS?
- Enumerations are a user defined data type which consist integral constants. In this, you can specify a set of values for a variable and the variable can select only one out of the set. It has a fixed set of constants.
- To define enumerations we use ‘enum’ keyword. Enumerations can be used to define days of a week, month, weathers, etc. The enum constants are static and final implicitly.
WHAT ARE THE ADVANTAGES OF USING ENUMERATIONS?
Some of the advantages of enum are:
- It can be used in switch case.
- It improves type safety.
- It can have fields, constructors and methods.
- It can implement many interfaces but cannot extend any class.
- It can be traversed.
NOW, LET US HAVE A LOOK AT THE SIMPLE EXAMPLE: