Default In Switch Case Java
Switch dayofweek case monday.
Default in switch case java. Code string dayofweek monday. Consider the following java program it declares an int named day whose value represents a day 1 7. No break is needed in the default case.
The default case can be used for performing a task when none of the cases is true. Switch case statement is used when we have number of options or choices and we may need to perform a different task for each choice. A switch statement can have an optional default case which must appear at the end of the switch.
I will explain this with an example. The syntax of switch case statement looks like this switch variable or an integer expression case constant.