01 Java Switch Statement introduction & Syntax

preview_player
Показать описание
In this tutorial, we discuss Java Switch Statement introduction & Syntax:

The Java switch statement executes one statement from multiple conditions. It is like an if-else-if ladder statement. The switch statement works with a byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long. Since Java 7, you can use strings in the switch statement.

In other words, the switch statement tests the equality of a variable against multiple values.

Points to Remember
There can be one or N number of case values for a switch expression.
The case value must be of switch expression type only. The case value must be literal or constant. It doesn't allow variables.
The case values must be unique. In case of duplicate value, it renders compile-time error.
The Java switch expression must be of byte, short, int, long (with its Wrapper type), enums and string.
Each case statement can have a break statement which is optional. When control reaches to the break statement, it jumps the control after the switch expression. If a break statement is not found, it executes the next case.
The case value can have a default label which is optional.

Syntax:

switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......

default:
code to be executed if all cases are not matched;
}

01 Java Switch Statement introduction & Syntax

01 Java Switch Statement introduction & Syntax

02 Java Switch Statement Example

03 03 Java Switch Statement is fall through

04 Java Switch Statement with String

Can we overload java main method? - Java Basic Tutorials

Method Overloading with TypePromotion

2 Method Overloading changing data type of arguments

Method Overloading changing no of arguments core Java

01 Method Overloading Introduction core Java

01 Java History

How to print Java Programming

Like, Share & Subscribe
Visite for more:
Рекомендации по теме
welcome to shbcf.ru