Java Program to show usage of Enum which prints the size of coffee mug
Program
class Coffee
{
enum CoffeeSize { SMALL, MEDIUM, LARGE }
CoffeeSize size;
}
public class CoffeeEnum
{
public static void main(String[] args)
{
Coffee coffee = new Coffee();
coffee.size = Coffee.CoffeeSize.MEDIUM;
System.out.println("Size of coffee mug is: " + coffee.size);
coffee.size = Coffee.CoffeeSize.SMALL;
System.out.println("Size of coffee mug is: " + coffee.size);
coffee.size = Coffee.CoffeeSize.LARGE;
System.out.println("Size of coffee mug is: " + coffee.size);
}
}
Output
Size of coffee mug is: MEDIUM
Size of coffee mug is: SMALL
Size of coffee mug is: LARGE