Что напечатает эта программа?

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
Метод foo() выбрасывает исключение, после чего ход выполнения программы меняется - мы "перепрыгиваем" через печать А сразу в обработчик исключения, где происходит печать В

Follow CodeGalaxy

Mobile Beta

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