What will be the output of following code?

class Main {
    public static void main(String[] args) {
        int[] array1 = {1, 2};
        for (long x : array1) {
            System.out.println(x);
        }
    }
}
Explanation
In this case array has int elements which are casted implicitly, as there is no precision lost with the cast and there is no compilation exception. The loop prints values in order.

Следи за CodeGalaxy

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

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