What will be printed as the result of the following program execution?

public class C {
    public static void main(String[] args) {
        
        try {
            foo();
            System.out.print("A ");
        } catch (Exception e) {
            System.out.print("B ");
        } finally {
            System.out.print("C ");
        }
    }

    private static void foo() throws Exception {
        try {
            System.out.print("A1 ");
            throw new Exception();
        } catch (Exception e) {
            System.out.print("B1 ");
            throw new Exception();
        } finally {
            System.out.print("C1 ");
        }
    }
}
Explanation
Method foo() throws an exception, then the program flow changes - we "jump" over the printing of A right to the exception handler, where the B the being printed.

Следи за CodeGalaxy

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

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