2D Array Creation and Access MCQ Practice

Question 1 of 10

A kiln logs unused glaze pots in a new grid. What text does this Java code display?

int[][] glaze = new int[2][3];
System.out.print(glaze[0][2]);
  1. A. 2
  2. B. 0
  3. C. 3
  4. D. null

Question 2 of 10

A ferry stores ticket prices in an initializer list. What text does this Java code display?

int[][] fares = { {12, 18, 21}, {9, 15, 27} };
System.out.print(fares[1][0]);
  1. A. 12
  2. B. 18
  3. C. 9
  4. D. 15

Question 3 of 10

A mural wall is allocated as a 4-by-6 tile grid. What text does this Java code display?

int[][] tiles = new int[4][6];
System.out.print(tiles.length + "," + tiles[0].length);
  1. A. 4,6
  2. B. 6,4
  3. C. 4,4
  4. D. 24,6

Question 4 of 10

A bakery treats one tray row as a 1D array. What text does this Java code display?

int[][] trays = { {3, 8, 1}, {5, 2, 9} };
int[] middle = trays[1];
System.out.print(middle[2]);
  1. A. 1
  2. B. 5
  3. C. 8
  4. D. 9

Question 5 of 10

A lighthouse stores whether each lamp is lit. What text does this Java code display?

boolean[][] lamps = new boolean[3][2];
System.out.print(lamps[2][1]);
  1. A. true
  2. B. false
  3. C. 0
  4. D. null

Question 6 of 10

A kiosk allocates poster titles but has not stored any yet. What text does this Java code display?

String[][] posters = new String[2][2];
System.out.print(posters[1][0]);
  1. A. null
  2. B. ""
  3. C. 0
  4. D. false

Question 7 of 10

A pond survey allocates depth readings. What text does this Java code display?

double[][] depths = new double[2][4];
System.out.print(depths[0][1]);
  1. A. null
  2. B. 4.0
  3. C. 0.0
  4. D. 0

Question 8 of 10

A quilt shop stores square IDs. Which access throws ArrayIndexOutOfBoundsException?

int[][] quilt = { {7, 2}, {4, 8}, {1, 5} };
  1. A. quilt[0][1]
  2. B. quilt[2][0]
  3. C. quilt[1][1]
  4. D. quilt[3][0]

Question 9 of 10

A harbor clerk updates one crate count. What text does this Java code display?

int[][] bins = { {10, 20}, {30, 40} };
bins[0][1] = 99;
System.out.print(bins[1][1] + "," + bins[0][1]);
  1. A. 40,99
  2. B. 99,99
  3. C. 20,99
  4. D. 40,20

Question 10 of 10

A recital lighting board stores dimmer values. The table shows the contents of board after the initializer runs. What text does this Java code display?

row Column 0 Column 1 Column 2
Row 0 5 8 3
Row 1 2 9 4
int[][] board = { {5, 8, 3}, {2, 9, 4} };
System.out.print(board[1][0]);
  1. A. 8
  2. B. 2
  3. C. 5
  4. D. 9