1.

Default switch case in Java

Answer»

A switch statement is a DECISION making statement in Java. It is used to CHECK a variable’s equality against a list of values and their subsequent statements. It is a multiway branch statement.

Each condition is called a case and the variable is checked for each case.

Syntax for switch case:

switch(EXPRESSION) {   case value1 :      // Statements      break; // optional     case value2 :      // Statements      break; // optional       .       .       .       .    default : // This is the default switch case      // Statements }

The default statement is optional, and can appear anywhere inside the switch block.

If there is no match with a constant expression, the statement associated with the default KEYWORD is executed. If the default keyword is not used, control passes to the statement FOLLOWING the switch block.



Discussion

No Comment Found