Tricky Java Questions

This Java quiz collects the gotchas that trip up even experienced developers in interviews. Expect integer caching, hidden casts, silent overflow, unboxing surprises and a loop that should fail but does not.

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

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

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

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

Вопрос 1 из 10

What does this print?

public class Main {
    public static void main(String[] args) {
        Integer a = 127, b = 127;
        Integer c = 128, d = 128;
        System.out.println((a == b) + " " + (c == d));
    }
}
Показать ответ

B. true false Autoboxing uses Integer.valueOf, which caches the values -128 to 127. a and b are the same cached object, while each 128 is a new object, so == compares two different references. Use equals().

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

  • Integer caching and == on wrappers
  • Unboxing null in a ternary expression
  • Hidden casts in compound assignment and silent overflow
  • String constants, Math.abs and Double.MIN_VALUE
  • Removing from a list in a for-each loop, and the equals/hashCode contract

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

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

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

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

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