Menu
Topics Index
...
`

Switch Output final819


If you need explanation Read this topic If you need explanation Read this topic

If you need Answer Take test on this topic

Switch Output final819
What will be the output of the program?
class Output
{
    final static short i = 2;
    public static int j = 0;
    
    public static void main(String [] args)
    {
        for (int k = 0; k < 3; k++)
        {
            switch (k)
            {
                case i : System.out.print(" 1 ");
                case i - 1 : System.out.print(" 2 ");
                default : System.out.print(" 0 ");
            }
        }
    }
}

A. 0 1 2
B. 0 1 2 0 2 0
C. 2 1 0 1 0 0
D. 0 2 0 1 2 0
E. Compilation Error
Topic: Static Keyword In Java final Keyword In Java

If you need explanation Read this topic If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans :d
first k= 0.. so 0 printed
next k=1 so 2 printed there is no break so 0 printed
next k= 2 so 1 2 0 are printed

Posted by Ananda Kumar    2014-04-15 03:44:12


answer is e compilation error..because At least one public class is required in main file... if given class is declared as public..then the answer would be..d..020120..

Posted by Sneha Rapool    2014-04-15 05:39:36


Congratulations Ananda Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-16 04:18:52


© meritcampus 2019

All Rights Reserved.

Open In App