Java OCA OCP Practice Question 1120

Question

Given the following code, what is the expected outcome?

public class Test { 
      public static void main(String [] a) { 
         int [] b = [1,2,3,4]; 
         System.out.println("a[2]=" + a[2]); 
      } 
} 
  • A. The code compiles but does not output anything.
  • B. "a[2]=3" is printed out to the console.
  • C. "a[2]=2" is printed out to the console.
  • D. The code does not compile.
  • E. None of the above.


D.

Note

The declaration of the integer array is incorrect.

An array is declared by using curly braces {} instead of square brackets [].




PreviousNext

Related