Menu
Topics Index
...
`

Nested Switch


If you need explanation Read this topic

If you need Answer Take test on this topic

Nested Switch
What will be the output of the following program?
public class MoreSwitches {
    public static void main(String args[]) {
        char status = 'P';
        int year = 3;
        switch (status) {
            case 'F' :
                System.out.print("Student Failed ");
            case 'P' :
                System.out.print("Student Passed ");
                switch (year) {
                    case 1 :
                        System.out.print(year + " Year");
                    case 2 :
                        System.out.print(year + " Year");
                    case 3 :
                        System.out.print(year + " Year");
                }
        }
    }
}

A. Student Passed 3 Year
B. Student FailedStudent Passed 3 Year3 Year3 Year
C. Some other output
D. Compilation Error 
E. 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.

A

Posted by Indrasena Reddy    2014-01-20 08:57:05


A

Posted by Indrasena Reddy    2014-01-20 08:57:15


Ans:A. The output will be Student Passed 3 Year. case with label P is executed and case 3 is executed in the nested switch.

Posted by Priyanka Madiraju    2014-01-20 09:02:01


some other output i.e  3 year                          only inner switch case 3 will execute

Posted by Shiva Kumar    2014-01-20 09:13:33


C

Posted by Shiva Kumar    2014-01-20 09:17:35


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

Posted by Merit Campus    2014-01-21 03:44:47


© meritcampus 2019

All Rights Reserved.

Open In App