Menu
Question Index
...

What will be the output of the following program?

public class ArrayInitializer {
    public static void main(String args[]) {
        int ranks[] = new int[4];
        ranks = {10, 20, 30, 40};
        int totalranks = 0;
        for (int rank : ranks) {
            totalranks++;
        }
        System.out.print(totalranks);
    }
}


4
0
Compilation Error
Runtime Error

Doubts

Problems

Topic: For-each Loop In Core Java Programming

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App