1Z0-803 · Question #18
Given the code fragment: What is the result?
The correct answer is B. Found Red. As there is no break statement after the case "Red" statement the case Blue statement will run as Note: The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluate
Question
Given the code fragment:
What is the result?
Exhibit
Options
- AFound Red
- BFound Red
- CFound Red
- DFound Red
How the community answered
(41 responses)- A2% (1)
- B88% (36)
- C2% (1)
- D7% (3)
Explanation
As there is no break statement after the case "Red" statement the case Blue statement will run as Note: The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluates its expression, then executes all statements that follow the matching case label. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocksfall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered.
Topics
Community Discussion
No community discussion yet for this question.
