Menu
Topics Index
...
`

Break the glass


If you need explanation Read this topic

If you need Answer Take test on this topic

Break the glass
What will be the output of the following program?
public class BreakTheGlass {
    public static void main(String[] args) {
        int x = 15;
        x = 10 + x - x + 35;
        switch (x) {
            case 35 :
                System.out.println("Switch 35");
                break;
            case 45 :
                System.out.println("Switch 45");
                break;
            case 55 :
                System.out.println("Switch 55");
                break;
            case 65 :
                System.out.println("Switch 65");
                break;
        }
    }
}

A. Switch 35
Switch 45
Switch 55
Switch 65
B. Switch 45
Switch 55
Switch 65
C. Switch 45
D. Compilation Error
E. Runtime Error
Topic: Using break in switch case Statement

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 is C since x=45 i.e 10+35

Posted by Soundarya Velugubantla    2014-01-16 12:34:42


C. is ans as ac to precedecies we get x=10+15-15+35 ie; only 10 +35 is considered and switched to 45 and then break encounters.

Posted by Shabaaz Shaikz    2014-01-16 12:42:53


C

Posted by Shravan Kumar    2014-01-16 15:32:02


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

Posted by Merit Campus    2014-01-17 04:00:52


© meritcampus 2019

All Rights Reserved.

Open In App