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…
- A.
a1 = 100;
- B.
a2 = 1000;
- C.
a3 = 10;
- 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.
Loading lesson…