Java Enum - The Coding Shala
Home >> Learn Java >> Java Enum Java Enum Java Enum is a special type of data type. Enum is used to make collections of constants. It can be used for days of the week or directions or solar system etc. The java enum is final static implicitly. When we define Java enum it creates a class of type enum so we can define java enum inside the class or outside the class it doesn't matter. Java enum can have fields, constructors and methods. Note: Constructors of the enum is always private. if we don't make it private java compiler make private constructor by defaults. Java enum can be easily used with if-else or switch statements. we can traverse through enum easily. we can't create a new instance of enum because of its private constructor. Enum may implement interfaces but cannot extend any class because it internally extends Enum class. The below example shows how to define enum and assign value to an enum type- //HOW TO Defin...