Menu
Question Index
...

What will be the output of the following program?

class DemoOnSwitch
{
    public static void main(String args[])
    {
        int firstVariable, secondVariable = 1;
        firstVariable = (secondVariable > 1) ? 2 : 1;
        switch (firstVariable)
        {
            case 0 :
                System.out.print(0);
                break;
            case 1 :
                System.out.print(1);
            case 2 :
                System.out.print(2);
                break;
            case 3 :
                System.out.print(3);
                break;
        }
    }
}


12
21
2
0123
Compilation Error or Runtime Error

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