Calling Class Methods FRQ Practice

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

Question 1 of 5

Class TramCar declares public static int seats() which returns 24.

(a) Write a class-qualified call from Depot that prints the result. (b) Explain why the class name appears before the dot. (c) Explain whether Depot must first construct a TramCar object.

Question 2 of 5

Both methods below are in class DockLog.

public static int tide()
{
    return 11;
}
public static int gap()
{
    return tide() - 3;
}

(a) What value does DockLog.gap() return? (b) Why may gap call tide without DockLog.? (c) Write the call another class would use to get that gap.

Question 3 of 5

TramCar.load(int standing) returns 24 + standing.

(a) Trace int cap = TramCar.load(9); and state cap. (b) Explain how the returned result is used in that statement. (c) Write one expression that prints 24 plus 9 without storing a variable, using a class-qualified call.

Question 4 of 5

Class Depot contains only main. TramCar defines public static void bell() which prints CLANG and public static int seats() which returns 24.

(a) Write a Depot statement that calls bell correctly. (b) Write a Depot statement that stores seats in int n. (c) Explain one compile error caused by writing seats() with no class name in Depot.

Question 5 of 5

A student says a static method updates the caller's int automatically.

public class TramCar
{
    public static int load(int standing)
    {
        standing = standing + 24;
        return standing;
    }
}

int riders = 6;
TramCar.load(riders);
System.out.print(riders);

(a) State the displayed value. (b) Correct the student's claim. (c) Show how to store the method result in riders.