What is the result?

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

Download Printable PDF. VALID exam to help you PASS.

One thought on “What is the result?

  1. 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.

    1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.