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.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback