Scope and Access FRQ Practice

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

Question 1 of 5

A method contains this loop.

int n = 3;
while (n > 0)
{
    int drop = n;
    n--;
}

(a) Identify the block where drop can be used. (b) State the value of n after the loop. (c) Explain whether System.out.print(drop); after the loop compiles.

Question 2 of 5

A method is declared as public void stamp(int mark).

(a) Identify whether mark is local and whether it may be declared public. (b) If stamp contains mark = 8; and the caller has int mark = 1; stamp(mark); state the caller's mark afterward. (c) State the scope of the parameter mark.

Question 3 of 5

A lamp method uses a parameter named watts.

public class Lamp
{
    private int watts = 60;
    public void dim(int watts)
    {
        watts = 40;
    }
    public int getWatts()
    {
        return watts;
    }
}

(a) State getWatts() after dim(40) is called on a new Lamp. (b) Explain which watts is assigned 40. (c) Explain why the instance field is unchanged.

Question 4 of 5

Complete the table for this fragment, then answer.

int left = 5;
if (left > 0)
{
    int inner = 2;
    left -= inner;
}
Name Block where it is declared Usable after the if?
left
inner

(a) Fill the table. (b) State left after the if. (c) Explain whether inner can be printed after the if.

Question 5 of 5

A shelf method uses a local loop variable and an instance field.

public class Shelf
{
    private int books = 14;
    public int box(int n)
    {
        int packed = 0;
        while (n > 0)
        {
            packed++;
            n--;
        }
        return packed;
    }
    public int getBooks()
    {
        return books;
    }
}

(a) State box(3) and getBooks() on a new Shelf after that call. (b) Explain whether n and packed exist after box returns. (c) Explain whether box's n is the same storage as the instance books.