Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (55.6k points)
I could not understand enumeration in Java. Please explain enumeration with an example.

1 Answer

0 votes
by (119k points)
edited by

Enumeration is also called as enum. The enumeration in java is a kind of class that contains a set of constants also called enumerators.

We can create enum by adding enum keyword before the class name. Declare the constant variables inside the enum and all these variables in enum should be in capital letters.

Example:

enum gameLevel {

  BEGINNER,

  INTERMEDIATE,

  ADVANCE

}

Use the dot operator to access enum variables:

gameLevel myVar = gameLevel.INTERMEDIATE;

I would suggest you enroll in this Java Certification program by Intellipaat in case you are interested to learn Java.

You can watch this video on the Java tutorial for beginners by Intellipaat for better understanding:

Related questions

0 votes
1 answer
asked May 17, 2023 in Java by neelimakv (32.5k points)
0 votes
1 answer
asked Apr 14, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 2, 2021 in Java by dev_sk2311 (45k points)

Browse Categories

...