Java OCA OCP Practice Question 828

Question

Given:

double myArray [][][] = new double [3][][]; 
double d = 100.0; 
double [][] myArray2 = new double [1][1]; 

Which of the following will not cause any problem at compile time or runtime?

Select 2 options

  • A. myArray [0] = d;
  • B. myArray [0] = myArray2;
  • C. myArray [0] = myArray2 [0];
  • D. myArray2 [1][1] = d;
  • E. myArray2 = myArray [0]


Correct Options are  : B E

Note

For Option A. myArray [0] = d;

myArray [0] should be a 2 dimensional array because myArray is a 3 dimensional array.

For Option C. myArray [0] = myArray2 [0];

myArray [0] should be a 2 dimensional array while myArray2 [0] is a one dimensional array.

For Option D. myArray2 [1][1] = d;

myArray2 [1][1] will cause an ArrayIndexOutofBoundsException because myArray2's length is only 1 and the indexing starts from 0.

To access the first element, you should use myArray2 [0][0].




PreviousNext

Related