QuestionQ118

Using Operators and Decision Constructs

Given this code fragment:

Question Image

What is the outcome?

  • A It results in a compile time error at line 18.
  • B It results in a compile time error at line 9.
  • C It prints : 1
  • D It results in a compile time error at lines at lines 12 and 15.
Explanation

A local variable declared within a switch statement block is in scope only until that block’s closing brace. Because color is referenced after the switch block ends, line 18 causes a compile-time error.

Community Discussion

No comments yet. Be the first to start the discussion!