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
Зареєструйся Зараз
або Підпишись на майбутні тести