case constants are evaluated from the top down
the first case constant that matches the switch's expression is the execution entry point.
once a case constant is matched, the JVM will execute the associated code block and subsequent code.
enum Color {red, green, blue}
public class MainClass{
public static void main(String [] args) {
Color c = Color.green;
switch(c) {
case red: System.out.print("red ");
case green: System.out.print("green ");
case blue: System.out.print("blue ");
default: System.out.println("done");
}
}
}
|