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

public class Switch {
    public static void main(String[] args) {
        int i = 3;
        switch(i) {
            default:
                System.out.println("default");
            case 1:
                System.out.println("1");
            case 2:
                System.out.println("2");
        }
    }
}
Explanation
case and default keywords can be located in any order. If a break keyword is not used, then the program will continue to the subsequent in case order .

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты