Enhanced For-Loop Type Mismatch
What prevents the following code from compiling?
public class Test {
public static void main(String[] args) {
int[] testGrades = {95, 88, 76, 100, 82};
for (String grade : testGrades) {
System.out.println(grade);
}
}
}
A
There is no compilation error; the code compiles successfully.
B
The array initializer syntax is incorrect due to misplaced commas.
C
The loop variable is declared as String even though the array holds int values.
D
The for-loop header is missing a colon between the variable and the array.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE