- To define a new type, Day.
- Variable of type Day can only store the values specified between the braces.
- Monday, Tuesday, ... Sunday are called enumeration constants.
- These names will correspond to integer values, starting from 0 in this case.
public class MainClass {
enum Day {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}
public static void main(String[] args) {
Day yesterday = Day.Thursday;
Day today = Day.Friday;
Day tomorrow = Day.Saturday;
System.out.println("Today is " + today);
System.out.println("Tomorrow will be " + tomorrow);
System.out.println("Yesterday was " + yesterday);
}
}
Today is Friday
Tomorrow will be Saturday
Yesterday was Thursday