Menu
Question Index
...

What will be the output of the following program.

class Directions
{
    public static void main(String s[])
    {
        char direction = 'N';
        char west = 'W';

        switch(direction)
        {
            case 'N':
                System.out.println("North");
                break;
            case 'E':
                System.out.println("East");
                break;
            case west:
                System.out.println("West");
                break;
            case 'S':
                System.out.println("South");
        }
    }
}


No Output
Compilation Error - since case 'S' does not have break
Compilation Error - since variable 'west' can not be used as case label
Runtime error
North

Doubts

Problems

Topic: switch Statement In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App