Enum in Java

  • Eclipse: Oxygen
  • Java: 1.8

Enum is used to define a set of constants in java. Not only constant by it could also call any method, constructor associated with it. Which will be seen further in the tutorial.

We should always use enum when a variable (especially a method parameter) can only take one from a small set of possible values.

Enums are default public static hence we can directly reference variable by Enum Name.

Demo class

Output

1
2
3
4

Learning class

Output

1
2
3
4

The above concept is explained that enum can be used more than one purpose, by the assignment of numbers to the enums and then access it by calling the original function.

Demo class

Output

Step 1 : learning Core Java

Learning class

Output

Step 1 : learning Core Java

Contributed by Poonam Tomar

 


VIEW COURSES

Buy me a coffee!

 

PayTM QR (INDIA)

  • Get video tutorials
  • Project files set
  • Get┬áCertified

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu