What is the result of the program:

class Main {
    public static void main(String[] args) {
        int[] array = {1, 2};
        int x;
        for (x : array) { 
            System.out.println(x);
        }
    }
}
Explanation
In for-each loop a variable that represents an item from array has to be declared with a type, otherwise we'll get a compilation error.

Follow CodeGalaxy

Mobile Beta

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