Array Creation and Access FRQ Practice

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

Question 1 of 5

A radio desk creates a signal-strength array with

int[] signals = new int[5];

(a) State the value of signals.length and explain why that value cannot later be assigned a different size. (b) State the value stored in every element immediately after creation. (c) State the smallest and largest valid indices. (d) State what happens if the program executes System.out.print(signals[5]);

Question 2 of 5

A yarn shop uses this initializer list, then overwrites one slot. Complete the table for the array after the assignment. Then state the displayed text.

int[] bins = {6, 1, 9, 4};
bins[2] = bins[0] + bins[3];
System.out.print(bins[1] + " " + bins[2]);
Index Value after assignment
0 6
1
2
3

Question 3 of 5

A dock records pylon heights, then tries two prints.

int[] pylons = {11, 8, 14};
pylons[1] = 20;
System.out.print(pylons[1]);
System.out.print(pylons[-1]);

(a) State the valid index range for pylons. (b) State what the first print would display if it ran alone. (c) Identify the exception from the second print and the index that caused it.

Question 4 of 5

A lantern shop keeps wick labels and lengths.

String[] labels = new String[3];
int[] mm = new int[3];
labels[0] = "hemp";
mm[2] = 40;

(a) State labels[1] and mm[0] after these statements. (b) Explain why those two defaults differ. (c) Write one statement that stores 25 in the last mm slot using mm.length.

Question 5 of 5

A hardware drawer stores Peg objects. Peg is defined as follows.

public class Peg
{
    private int holes;
    public Peg(int holes)
    {
        this.holes = holes;
    }
    public int getHoles()
    {
        return holes;
    }
}

Then this client code runs.

Peg[] rack = new Peg[2];
rack[1] = new Peg(4);

(a) State rack.length and rack[0] immediately after new Peg[2], before the assignment. (b) After the assignment, state whether rack[1] == null and the value of rack[1].getHoles(). (c) State what happens if the client then executes rack[2] = new Peg(8);