The switch statement is a multiway branch statement. The general form of the switch statement is given below:
case value1://statements
break;
case value2://statements
break;
.
.
default:
//default statements
}
The expression must be of int, char, byte, or short data type and the data type of the values specified must be compatible with the expression.
Each case value must be a unique literal value. Variables are not allowed as case values.
The execution process of a switch statement is as follows:
The value of the expression is matched with each of the literal values in the case statements. If a match is found then the code sequence following that case statement is executed. If none of the values match, then the default statement is executed.
If the default statement is not given and no matching value is found, then no further action is taken.
- Download practice question and study guide for master-ciw-enterprise-developer for exam.
- Click here to download scbcd test study guide and practice question.
- Best exam simulation SUN scdjws download free trial.
- Click here to get free scja SCJA exam practice questions.
- Click here to download scjp test study guide and practice question.
- Download practice question and study guide for scjp-5-0 for exam.
- Click here to download scmad test study guide and practice question.
- Click here to get free scwcd SCWCD exam practice questions.
- Click here to get free CX310-019 SCJA exam practice questions.
- Download free practice test for SUN Java 5.0 exam.
- Pass SUN CX310-065 - SCJP 6.0
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.