Java - Enum Type Super class

What is Enum Type Super class

Every enum type implicitly extends java.lang.Enum class.

An enum type is implicitly final.

The compiler adds two static methods, values() and valueOf(), to every enum type.

The Enum class implements the java.lang.Comparable and java.io.Serializable interfaces.

The following code snippet shows how to compare two enum constants:

Demo

enum Level {
  LOW, MEDIUM, HIGH, URGENT;/*from  w  w w .j  av a  2  s .  c  om*/
}

public class Main {
  public static void main(String[] args) {
    Level s1 = Level.LOW;
    Level s2 = Level.HIGH;

    // s1.compareTo(s2) returns s1.ordinal() - s2.ordinal()
    int diff = s1.compareTo(s2);
    if (diff > 0) {
      System.out.println(s1 + " occurs after " + s2);
    } else {
      System.out.println(s1 + " occurs before " + s2);
    }
  }
}

Result