Which statement in this code is unreachable in switch(x) ? { case 1: a1 = 100;…

2021

Which statement in this code is unreachable in switch(x) ? { case 1: a1 = 100; case 2: a2 = 1000; a3 = 10; break; a4 = 10000; }

Answer: D. a4 = 10000;In Java, a break statement immediately exits the switch block. Any code following a break within the same case block is unreachable because execution…

  1. A.

    a1 = 100;

  2. B.

    a2 = 1000;

  3. C.

    a3 = 10;

  4. D.

    a4 = 10000;

Attempted by 443 students.

Show answer & explanation

Correct answer: D

In Java, a break statement immediately exits the switch block. Any code following a break within the same case block is unreachable because execution terminates before reaching it.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…