Java OCA OCP Practice Question 1410

Question

Which statements best describe the result of this code? (Choose two.)

package mypkg; //from w ww.  java  2  s.c o m
public class Main { 

  public static void main(String... args) { 
     String[] a = new String[] { "A", "B", "C" }; 
     String[] times = new String[] { "Day", "Night" }; 
        for (int i = 0, j = 0; i < a.length; i++, j++) 
           System.out.println(a[i] + " " + times[j]); 
  } 
} 
  • A. The println causes one line of output.
  • B. The println causes two lines of output.
  • C. The println causes three lines of output.
  • D. The code terminates successfully.
  • E. The code throws an exception at runtime.


B, E.

Note

The first two iterations through the loop complete successfully, making Option B correct.

The two arrays are not the same size and the for loop only checks the size of the first one.

The third iteration throws an exception, making Option E correct.




PreviousNext

Related