Enums
An enum defines fixed constants. values() lists them and switch works on them.
Example
public class Main {
enum Level { LOW, MID, HIGH }
public static void main(String[] args) {
Level l = Level.HIGH;
System.out.println(l + " " + l.ordinal() + " " + Level.values().length);
}
}Result
HIGH 2 3
Exercise
Declare an enum.
Color { RED, BLUE }Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.