Given the code fragment:
What is the result?
A. Found Red
Found Default
B. Found Teal
C. Found Red
Found Blue
Found Teal
D. Found Red
Found Blue
Found Teal
Found Default
E. Found Default
Given the code fragment:
What is the result?
A. Found Red
Found Default
B. Found Teal
C. Found Red
Found Blue
Found Teal
D. Found Red
Found Blue
Found Teal
Found Default
E. Found Default
E is the correct answer.
Note the declaration and assignment String color = “teal” (lowercase T) which will not match case “Teal”, since Java is case-sensitive.
you are right!
public class Test {
public static void main(String[] args) {
String color = “teal”;
switch (color) {
case “Red”:
System.out.println(“Found Red”);
case “Blue”:
System.out.println(“Found Blue”);
break;
case “Teal”:
System.out.println(“Found Teal”);
break;
default:
System.out.println(“Found Default”);
}
}
}
Output:
Found Default