What will be the result of compilation and execution of the following code:

public class Test {
    public static void main(String[] s){
        long c = 1;
        switch(c)
        {
            case 1: c = 3; break;
            case 3: c = 4; break;
        }
        System.out.println(c);
    }
}
Explanation
A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types, the String class (since JDK 7), and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer.

switch does not work with long.

( https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html )

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes