What is the result of the following program:

class Main {
    public static void main(String[] args) {
        long[] array2 = {3, 4};
        for (int x : array2) { 
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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes