Menu
Question Index
...

What will be the output of the following program?

public class Final
{
    final static short x = 2;
    public static int y = 0;
    
    public static void main(String [] args)
    {
        for (int z = 0; z < 3; z++)

            switch (z)
            {
                case y: System.out.print("0 ");    // LINE M

                case x - 1: System.out.print("1 "); // LINE N

                case x: System.out.print("2 ");    // LINE O
            }
    }
}


0 1 2
0 1 2 1 2 2
Compilation fails at LINE M
Compilation fails at LINE N
Compilation Error at some other place

Doubts

Problems

Topic: final Keyword 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