Class Variables and Methods FRQ Practice

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

Question 1 of 5

A blacksmith class tries to report heat from a class method.

public class Forge
{
    private int coals;
    public Forge(int coals)
    {
        this.coals = coals;
    }
    public int getCoals()
    {
        return coals;
    }
    public static int heat()
    {
        return coals * 2;
    }
}

(a) Explain why heat does not compile. (b) Rewrite heat so it takes a Forge parameter and uses getCoals. (c) State the value of Forge.heat(new Forge(6)) after that rewrite.

Question 2 of 5

A scorekeeper already has class storage.

public class Tally
{
    private static int base = 5;
    public static int bump()
    {
        return base + 1;
    }
}

(a) Write a class method named triple that returns bump() + bump() + bump(). (b) State Tally.triple(). (c) Explain why triple may call bump and why it still cannot name a missing instance field named mark.

Question 3 of 5

Trace the sled crew helper.

public class Sled
{
    private int riders;
    public Sled(int riders)
    {
        this.riders = riders;
    }
    public int getRiders()
    {
        return riders;
    }
    public static int crew(Sled a, Sled b)
    {
        return a.getRiders() + b.getRiders() - 1;
    }
}

Sled front = new Sled(4);
Sled back = new Sled(3);
System.out.print(Sled.crew(front, back));

(a) State getRiders for front and back. (b) State the displayed text. (c) Explain why crew can call getRiders twice even though crew is static.

Question 4 of 5

A token press shares a mint count.

public class Token
{
    public static int minted = 2;
    private int face;
    public Token(int face)
    {
        this.face = face;
        minted++;
    }
    public int getFace()
    {
        return face;
    }
}

Token red = new Token(1);
Token blue = new Token(8);

(a) State Token.minted after both objects are constructed. (b) Explain why red and blue do not each store a separate minted value. (c) Write the statement from another class that prints minted using the class name.

Question 5 of 5

A dockyard keeps a constant slip count and a shared boat count.

public class Dock
{
    public static final int SLIPS = 6;
    public static int boats = 1;
    private int ropes;
    public Dock(int ropes)
    {
        this.ropes = ropes;
        boats += ropes;
    }
    public int getRopes()
    {
        return ropes;
    }
}

Dock north = new Dock(2);
Dock south = new Dock(1);

(a) Complete the table for boats after each constructor, then state Dock.boats and Dock.SLIPS. (b) Explain why SLIPS cannot be assigned 10 in a method. (c) Explain how another class reads boats.

Event Dock.boats north.getRopes() south.getRopes()
After north is constructed 2 n/a
After south is constructed 2 1