Multiple choice technology programming languages

class Demo { public static void main(String[] args) { int[] x = {7,6,5,4,3,2,1}; // insert code here System.out.print(y + " "); } } } Which, inserted independently at line 4, compiles? (Choose all that apply.)

  1. for(int y : x) {

  2. for(x : Int y) {

  3. int y = 0; for(y : x) {

  4. for(int y=0, z=0; z<x.length; z++) { y = x[z];

  5. for(int y=0, int z=0, int z=0; z<x.length; z++) { y = x[z];

  6. int y = 0; for(int z=0; z<x.length; z++) { y = x[z];

Reveal answer Fill a bubble to check yourself
A,F Correct answer
Explanation

Option A is the enhanced for loop syntax - correct. Option F declares y before the loop and uses traditional for loop to iterate - correct. Options B, C, D, E have syntax errors: wrong order in B, wrong syntax in C, incorrect declaration in E (int z declared twice in for-init). Only A and F compile independently.