Menu
Question Index
...

What will be the output of the following program.

class WeekDays
{
    public static void main(String s[])
    {
        int day = 15;
        
        switch(day)
        {
            case 1:
                System.out.println("Monday");
            case 2:
                System.out.println("Tuesday");
            case 3:
                System.out.println("Wednesday");
            case 4:
                System.out.println("Thursday");
            case 5:
                System.out.println("Friday");
            default:
                System.out.println("Weekend");
                break;
        }
    }
}


Weekend
Compilation Error - since no case matches day 15
Runtime Error - since day can be maximum of 7
Monday
Tuesday
Wednesday
Thursday
Friday
Weekend

Doubts

Problems

Topic: Using break in switch case Statement

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App