What will be printed into console after executing next piece of code:

public class Test {
    public void checkCase(int i) {
        switch (i&01) {
            case 1:
                System.out.println("Case 1");
            case 2:
                System.out.println("Case 2");
            default:
                System.out.println("Default");
            case 3:
                System.out.println("Case 3");
        }
    }
    public static void main(String[] args) {
        Test test = new Test();
        test.checkCase(-1);
    }
} 
Explanation
Result of -1 & 1 is 1. Case statements do not have break statement, so all of the strings will be printed.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback