Array Creation and Access MCQ Practice

Question 1 of 10

An ice rink lists locker numbers with an initializer. What text does this Java code display?

int[] lockers = {11, 14, 9};
System.out.print(lockers.length);
  1. A. 3
  2. B. 2
  3. C. 11
  4. D. 0

Question 2 of 10

A greenhouse starts humidity slots. What text does this Java code display?

double[] humid = new double[2];
System.out.print(humid[0] + " " + humid[1]);
  1. A. null null
  2. B. 0 0
  3. C. 0.0 0.0
  4. D. 2.0 2.0

Question 3 of 10

A studio records whether lamps are on. What text does this Java code display?

boolean[] open = {true, false, true};
System.out.print(open[1]);
  1. A. true
  2. B. false
  3. C. 0
  4. D. null

Question 4 of 10

A dye vat count in the middle slot is replaced. What text does this Java code display?

int[] vats = {5, 5, 5};
vats[1] = 12;
System.out.print(vats[0] + vats[1] + vats[2]);
  1. A. 15
  2. B. 36
  3. C. 5
  4. D. 22

Question 5 of 10

A bolt drawer tries to print one count. What happens when this Java code runs?

int[] bolts = {4, 6};
System.out.print(bolts[2]);
  1. A. The program displays 6
  2. B. The program displays 0
  3. C. An ArrayIndexOutOfBoundsException is thrown
  4. D. The program displays 2

Question 6 of 10

A cloth stall stores dye names. What text does this Java code display?

String[] dyes = {"red", "navy", "gold"};
System.out.print(dyes[0].length() + dyes[2].length());
  1. A. 7
  2. B. 3
  3. C. 4
  4. D. 9

Question 7 of 10

A clerk creates int[] row = new int[8];. Which statement is true?

  1. A. row.length() returns 8
  2. B. row.length is 8 and stays 8
  3. C. row[8] = 1 is a valid assignment
  4. D. Assigning row[10] grows the array to length 11

Question 8 of 10

A pair of ferry lanes is swapped using []. What text does this Java code display?

int[] pair = {3, 9};
int temp = pair[0];
pair[0] = pair[1];
pair[1] = temp;
System.out.print(pair[0] + " " + pair[1]);
  1. A. 3 9
  2. B. 3 3
  3. C. 9 9
  4. D. 9 3

Question 9 of 10

A scoreboard creates int[] marks = new int[10];. Which expression refers to the last element?

  1. A. marks[marks.length - 1]
  2. B. marks[marks.length]
  3. C. marks[10]
  4. D. marks[9 + 1]

Question 10 of 10

A conservatory updates one recorded temperature. What text does this Java code display?

double[] temps = {16.0, 18.5, 17.0};
temps[2] = temps[0] + 1.5;
System.out.print(temps[2]);
  1. A. 17.0
  2. B. 18.5
  3. C. 16.0
  4. D. 17.5