What is the result of the following program:

class Main {
    public static void main(String[] args) {
        long[] array2 = {3, 4};
        for (int x : array2) { 
            System.out.println(x);
        }
    }
}
Explanation
The type of the loop variable must be compatible by assignment with the type of the array elements.
Code will compile if you change the type of elements in the array to int or if you change the type of a loop variable to long.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести