Java - What is the output: switch on enum value

Question

What is the output from the following code

enum Level {
  LOW, MEDIUM, HIGH, URGENT;
}

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

    System.out.println(getValue(Level.LOW));
    System.out.println(getValue(s2));
    System.out.println(getValue(s1));
  }

  public static int getValue(Level severity) {
    int days = 0;
    switch (severity) {
    // Must use the unqualified name LOW, not Level.LOW
    case LOW:
      days = 30;
      break;
    case MEDIUM:
      days = 15;
      break;
    case HIGH:
      days = 7;
      break;
    case URGENT:
      days = 1;
      break;
    }

    return days;
  }
}


Click to view the answer

30
7
Exception in thread "main" java.lang.NullPointerException
	at Main.getValue(Main.java:17)
	at Main.main(Main.java:12)

Note

You do not need to handle the exceptional case of receiving a null value.

If the enum expression of the switch statement evaluates to null, it throws a NullPointerException.