// enums actually inherit from Enum public enum Month { // elements of enum are really subclasses JANUARY(31), FEBRUARY(28) { // can override methods from enum // february's days depend on leap year public int getDays() { // using static var of enum if (leapyear) { return days + 1; } // calling overridden method return super.getDays(); } }, MARCH(31), APRIL(30), MAY(31), JUNE(30), JULY(31), AUGUST(31), SEPTEMBER(30), OCTOBER(31), NOVEMBER(30), DECEMBER(31); protected final int days; Month(int d) { days = d; } public int getDays() { return days; } public String toString() { // class Enum has a toString return super.toString() + " is a month with " + getDays() + " days."; } // enums can have statics too private static boolean leapyear; public static boolean getLeapyear() { return leapyear; } public static void setLeapYear(boolean b) { leapyear = b; } }