Array Creation and Access MCQ Practice

Question 1 of 10

A greenhouse clerk creates an array of tray counts. What text does this Java code display?

int[] trays = new int[6];
System.out.print(trays.length);
  1. A. 5
  2. B. 6
  3. C. 0
  4. D. 7

Question 2 of 10

A kiln log starts empty shelves. What text does this Java code display?

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

Question 3 of 10

A ferry booth records ticket leftovers with an initializer list. What text does this Java code display?

int[] tickets = {12, 8, 15, 4};
System.out.print(tickets[2]);
  1. A. 12
  2. B. 8
  3. C. 4
  4. D. 15

Question 4 of 10

An orchard scale prints the last crate count. What text does this Java code display?

int[] crates = {9, 3, 7};
System.out.print(crates[crates.length - 1]);
  1. A. 9
  2. B. 3
  3. C. 7
  4. D. 2

Question 5 of 10

A marina merges two slip counts into the first slot. What text does this Java code display?

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

Question 6 of 10

A quilt booth tries to print one patch count. What happens when this Java code runs?

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

Question 7 of 10

A weather desk lists claimed defaults after new. Which option correctly completes the three empty cells?

Array created Value at index 0
new int[3] 0
new double[3]
new boolean[3]
new String[3]
  1. A. 0, false, ""
  2. B. 0.0, true, null
  3. C. 0.0, false, ""
  4. D. 0.0, false, null

Question 8 of 10

A kiosk stores badge labels. What text does this Java code display?

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

Question 9 of 10

A yarn bin array nums has already been created and has length 4. Which statement is true?

  1. A. nums[4] is the last element
  2. B. Valid indices are 0, 1, 2, and 3
  3. C. nums.length can be assigned 5 to grow the array
  4. D. nums[-1] wraps around to the last element

Question 10 of 10

A bakery starts a pan-count array, then fills two slots. What text does this Java code display?

int[] pans = new int[4];
pans[1] = 8;
pans[3] = pans[1] + 2;
System.out.print(pans[0] + pans[1] + pans[2] + pans[3]);
  1. A. 20
  2. B. 10
  3. C. 18
  4. D. 8