Array Creation and Access FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A ferry gate tracks whether three ramps are clear.

boolean[] clear = new boolean[3];
clear[1] = true;

(a) State the three stored values immediately after new boolean[3], before the assignment. (b) State the three stored values after the assignment. (c) State clear.length and the last valid index.

Question 2 of 5

Complete the missing table cells after this greenhouse code runs. Then state the displayed text.

int[] pots = {8, 3, 5, 2};
pots[0] = pots[3];
pots[3] = 9;
System.out.print(pots[0] + pots[1] + pots[3]);
Index After initializer After both assignments
0 8
1 3
2
3 2

Question 3 of 5

A marina tries this fragment.

int[] slips = {7, 4, 9, 1};
System.out.print(slips[slips.length - 1]);
System.out.print(slips[4]);

(a) State slips.length and the index used by the first print, plus the displayed digit from that print. (b) Identify the exception from the second print and explain it using the valid index range. (c) Write a replacement for the second print that displays the first element instead.

Question 4 of 5

A kiosk can create labels in two ways.

String[] a = new String[2];
a[0] = "dock";
String[] b = {"dock", "pier"};

(a) State a[1] and b[1] after this code. (b) State a.length and b.length. (c) Explain one difference between creation with new String[2] and creation with an initializer list.

Question 5 of 5

A wick tray uses this class and client code.

public class Wick
{
    private int mm;
    public Wick(int mm)
    {
        this.mm = mm;
    }
    public int getMm()
    {
        return mm;
    }
}

Wick[] tray = new Wick[3];
tray[0] = new Wick(12);
tray[2] = tray[0];

(a) State tray[1] after these statements. (b) State tray[0].getMm() and tray[2].getMm(). (c) State tray.length and explain whether assigning tray[2] = new Wick(40) would change that length.