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