What will the following code print:

public static void main(String[] args) {
    Integer i = 10;
    Integer x = 10;
    if (x == i) {
        System.out.print("true");
    } else {
        System.out.print("false");
    }
}
Explanation
256 Integer objects are created in the range of -128 to 127 which are all stored in an Integer array. So when creating an object using Integer.valueOf or directly assigning a value to an Integer within the range of -128 to 127 the same object will be returned.

Следи за CodeGalaxy

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

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