Computer Applications | Java | Class 9 | ICSE | 2026 Examination
Conditional Construct in Java | Class 9 | Computer Applications | ICSE
Java Switch Case Fall Through Explained
Default in Beginning, Middle, or End? Switch Case in Java Explained!
In Lecture 52, we learned the basics of the switch-case construct. Now, we'll explore advanced concepts that are crucial for ICSE examinations, including fall-through behavior, default positioning, program termination, and case grouping. These topics frequently appear in ICSE board questions as output-based problems.
Fall-through occurs when the code execution continues from one case to the next without encountering a break statement. After a matching case block is executed, if there's no break statement, the control flow will "fall through" to the subsequent case blocks until a break is encountered or the switch statement ends.
Real-World Analogy: Imagine a staircase where each step represents a case. Normally, you stop at your desired floor (case) and exit through a door (break). But if the door is missing (no break), you continue walking down to the next floor, and the next, until you find a door or reach the bottom.
Example 1: Unintentional Fall-Through
class FallThroughDemo1 {
public static void main(String args[]) {
int number = 1;
switch (number) {
case 1:
System.out.println("Value of number is one");
case 2:
System.out.println("Value of number is two");
case 3:
System.out.println("Value of number is three");
default:
System.out.println("Value of number is greater than three");
}
}
}
Output:
Value of number is one
Value of number is two
Value of number is three
Value of number is greater than three
Explanation: Even though number equals 1, all subsequent cases execute because there are no break statements. Case 1 matches and prints "Value of number is one". Since there's no break, program control falls through to case 2, executing its println statement. This continues through case 3 and even the default case.
Example 2: Controlled Fall-Through