Menu
Topics Index
...
`

print statements by using Switch1487


If you need explanation Read this topic

If you need Answer Take test on this topic

print statements by using Switch1487
What will be the output of the following program?
public class DemoOnSwitchCase
{
    public static void main(String args[])
    {
        int variable = 7;
        switch (variable++)
        {
            case 7 :
                switch (variable--)
                {
                    default :
                        System.out.print(variable);
                    case 7 :
                }
            default :
                System.out.print("wonders");
        }
    }
}

A. 7wonders
B. wonders7
C. wonders
D. 6
E. Compilation Error or Runtime Error
Topic: Nested switch Statements In Java

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.

c

Posted by Arul Palanisamy    2014-07-31 04:01:54


Answer is A 7wonders because the default statement in the inner switch will be executed and the default statement in the outer switch will be executed in order to give an output of 7wonders

Posted by Sai Avinash    2014-07-31 04:02:11


ns is A..cntri wl enter into inner swtch thn default wl executs n thr is no break so wonders wil print

Posted by Uday Kumar    2014-07-31 04:02:35


ans C, first variable in switch is 7, and variable is incremented so inner switch does not contain 8 , it cant execute so it prints default statement "wonders".

Posted by Damu Surya    2014-07-31 04:07:22


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

Posted by Merit Campus    2014-08-01 05:16:47


© meritcampus 2019

All Rights Reserved.

Open In App