enum methods java code example

Example 1: Enums injava

public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY 
}

Example 2: enum java

public enum AlertLevel {
	Undefined(0),
	Ok(1),
	Warning(2),
	Alarm(3);
}

Example 3: enum java

private enum VarState {
	INIT, 
	TRUE, 
  	FALSE,
	UNSATISFIABLE 
}

Example 4: java enum

public class DaysOfTheWeek {

    public enum Days {m, t, w, r, f, sat, s};
  	    public static void main(String[] args) {
          Days d = Days.t; 
          System.out.println(d);
          //the output would be t
        }
}

Example 5: enum with methods in java example

public enum Level {
    HIGH{
        @Override
        public String asLowerCase() {
            return HIGH.toString().toLowerCase();
        }
    },
    MEDIUM{
        @Override
        public String asLowerCase() {
            return MEDIUM.toString().toLowerCase();
        }
    },
    LOW{
        @Override
        public String asLowerCase() {
            return LOW.toString().toLowerCase();
        }
    };

    public abstract String asLowerCase();
}

Tags:

Java Example