Квиз по Java: try, catch & finally

This Java quiz walks through try, catch and finally, including the cases that surprise people, like a return inside finally. You will also trace try-with-resources and see when resources get closed.

Средний 10 вопроса ~6 минуты Проходной балл: 80% Java 17

Выберите режим

Вы играете как гость: войдите, чтобы сохранить XP и серию.

Пример вопроса

Вопрос 1 из 10

What does this print?

public class Main {
    static String test() {
        try {
            return "try";
        } finally {
            System.out.print("finally ");
        }
    }

    public static void main(String[] args) {
        System.out.println(test());
    }
}
Показать ответ

B. finally try The return value is computed first, then finally runs before the method actually returns. So finally is printed inside test(), and try is printed afterwards by main.

Что проверяет этот квиз

  • The order of try, catch, finally and the code after them
  • finally after return, and return inside finally
  • Returning a primitive vs an object from try
  • Catch block order and exceptions thrown from catch
  • Try-with-resources, AutoCloseable and close order

Частые вопросы

Нужен ли аккаунт?

Нет. Играть может любой. Войдите, чтобы сохранять XP, серию, значки и историю.

Можно пройти ещё раз?

Да. Лучший результат сохраняется, а вопросы и ответы каждый раз перемешиваются.