Java OCA OCP Practice Question 1105

Question

Which of the following is equivalent to this code snippet given an array of String objects?

for (int i=0; i<s.length; i++) 
   System.out.println(s[i]); 
  • A. for (String f = s) System.out.println(f);
  • B. for (String f : s) System.out.println(f);
  • C. for (String = s) System.out.println(it);
  • D. None of the above


B.

Note

The for-each loop uses a variable and colon as the syntax, making Option B correct.




PreviousNext

Related