nerdexam
Oracle

1Z0-809 · Question #55

Given the code fragment: String color = "teal"; switch (color) { case "Red": System.out.println("Found Red"); case "Blue": System.out.println("Found Blue"); break; case "Teal"…

The correct answer is E. Found Default. Option E is correct because Java's switch statement uses case-sensitive string comparison, and "teal" (all lowercase) does not match any of the case labels "Red", "Blue", or "Teal" (capital T) - so execution jumps directly to default, printing "Found Default". Why the…

Question

Given the code fragment: 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"); } What is the result?

Options

  • AFound Red Found Default
  • BFound Teal
  • CFound Red Found Blue Found Teal
  • DFound Red Found Blue Found Teal Found Default
  • EFound Default

How the community answered

(35 responses)
  • A
    11% (4)
  • B
    6% (2)
  • D
    3% (1)
  • E
    80% (28)

Explanation

Option E is correct because Java's switch statement uses case-sensitive string comparison, and "teal" (all lowercase) does not match any of the case labels "Red", "Blue", or "Teal" (capital T) - so execution jumps directly to default, printing "Found Default".

Why the distractors fail:

  • A is wrong because "Red" never matches "teal", so that case block is never entered.
  • B is wrong for the same case-sensitivity reason: "Teal""teal", so that case is skipped.
  • C and D are wrong because no case label matches; fall-through only occurs within a switch once a matching case is entered - it cannot chain across unmatched cases.

Memory tip: Think of Java String switches as using .equals(), not equalsIgnoreCase() - if the capitalization isn't pixel-perfect, the case won't fire. When you see a String in a switch, always double-check the exact casing of both the variable's value and the case literals.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice