Enum Basics
enum MyEnum nbsp; //Defines enum type
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public class EnumDemo //EnumDemo is a class using enum MyEnum
static MyEnum my;
public EnumDemoMyEnum day) {
switch (day) {
case SUNDAY:
System.out.println"Today is Sunday");
break;
case MONDAY:
System.out.println("Today is Monday");
break;
case TUESDAY:
System.out.println"Today is Tuesday");
break;
case WEDNESDAY:
System.out.println("Today is Wednesday");
break;
case THURSDAY:
System.out.println"Today is Thursday");
break;
case FRIDAY:
System.out.println("Today is Friday");
break;
case SATURDAY:
System.out.println"Today is Saturday");
break;
}
}
public static void main(String[] args) {
EnumDemo ed1 = new EnumDemo(my.SUNDAY);
EnumDemo ed2 = new EnumDemo(my.MONDAY);
EnumDemo ed3 = new EnumDemo(my.TUESDAY);
EnumDemo ed4 = new EnumDemo(my.WEDNESDAY);
EnumDemo ed5 = new EnumDemo(my.THURSDAY);
EnumDemo ed6 = new EnumDemo(my.FRIDAY);
EnumDemo ed7 = new EnumDemo(my.SATURDAY);
}
}
Output:
Today is Sunday
Today is Monday
Today is Tuesday
Today is Wednesday
Today is Thursday
Today is Friday
Today is Saturday