What variable type of red allows the following application to compile?
public class MyClass { public static void main(String[] args) { int myField = 10; red = 5; /*from w w w. j a v a 2s . c om*/ switch(myField) { default: System.out.print("Home"); break; case red: System.out.print("Away"); } } }
D.
The value of a case statement must be constant, a literal value, or final variable.
Since red is missing the final attribute, no variable type allows the code to compile, making Option D the correct answer.