What is the default switch case?

 switch case in Java

Last updated:8/27/2019 3:17:03 AM

1 Answers

Shrikant Mishra
Shrikant Mishra

Ans: In a switch statement, the default case is executed when no other switch condition matches. The default case is an optional case. It can be declared only once all other switch cases have been coded.

In the below example, when the score is not 1 or 2, the default case is used.

public class switchExample {

    int score = 4;
    public static void main(String args[]) {
        switch (score) {
            case 1:
                system.out.println('Score is 1');
                break;
            case 2:
                system.out.println('Score is 2');
                break;
            default:
                system.out.println('Default Case');
        }
    }
}

Answer