Java OCA OCP Practice Question 2883

Question

Given this code in a method:

5.     boolean[] ba = {true, false};  
6.     short[][] gr = {{1,2}, {3,4}};  
7.     int i = 0;  
8.     for( ; i < 10; ) i++;  
9.     for(short s: gr) ;  
10.    for(int j = 0, k = 10; k > j; ++j, k--) ;  
11.    for(int j = 0; j < 3; System.out.println(j++)) ;  
12.    for(Boolean b: ba) ; 

What is the result? (Choose all that apply.)

  • A. Compilation succeeds.
  • B. Compilation fails due to an error on line 8.
  • C. Compilation fails due to an error on line 9.
  • D. Compilation fails due to an error on line 10.
  • E. Compilation fails due to an error on line 11.
  • F. Compilation fails due to an error on line 12.


C is correct.

Note

"gr" is a two-dimensional array, you can't stuff one of its dimensions (a one-dimensional array) into a primitive.

A, B, D, E, and F are incorrect because all of the other "for" loop syntaxes are legal.




PreviousNext

Related