Enum concept introduced in JDK 1.5 version.
Java enum more powerful than other language.
The main purpose of enum is if we want to developed or represent group of constant then we should go for enum.
Internally enum represent as liked this Class concepts
Every enum by default public static final
Every constant represent as object of type enum
Public static final Friend sachin=new Friend();
Public static final Friend atish=new Friend();
Specialty of java enum:
In old language we represent only constant but in java enum
we declare variable,constructor and method also and enum can have main method
also we run enum from cmd also
i.e java enum is more powerful than other languages;
public static void main(String args)
Some valid combination java enum:
- · It can be inside the class.
- · class can be inside enum.
- But inside method does not allowed
enum is direct child class of java.lang.Enum so we cannot extend any other enum
so that it cannot extend any another enum.
it can implement any number of interface.
One of the most important interview question I faced