this Keyword FRQ Practice

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

Question 1 of 5

An oven constructor is unfinished.

class Oven {
    private int heat;
    public Oven(int heat) {
        /* missing assignment */
    }
    public int reading() {
        return this.heat;
    }
}

(a) Write the constructor assignment that stores the parameter in the field. (b) After Oven deck = new Oven(375); what does System.out.print(deck.reading()); display?

Question 2 of 5

A ferry window is supposed to pass the current pass to a dock.

class FerryPass {
    private int fare;
    public FerryPass(int fare) {
        this.fare = fare;
    }
    public int cost() {
        return this.fare;
    }
    public void present(Dock d) {
        /* pass the current FerryPass */
    }
}
class Dock {
    public void punch(FerryPass p) {
        System.out.print(p.cost());
    }
}

FerryPass dawn = new FerryPass(11);
Dock pier = new Dock();
dawn.present(pier);

(a) Write the present body that passes this to punch. (b) Identify the object this refers to during dawn.present(pier). (c) State the displayed text.

Question 3 of 5

Complete the missing table cells for this locker. Then explain why spin's parameter named combo is not the field.

class Locker {
    private int combo;
    public Locker(int combo) {
        this.combo = combo;
    }
    public void spin(int combo) {
        this.combo += combo;
    }
}

Locker gym = new Locker(15);
gym.spin(3);
Step Statement Field combo Parameter combo
1 constructor body starts 0 15
2 this.combo = combo 15
3 spin(3) body starts 15 3
4 this.combo += combo 3

Question 4 of 5

A greenhouse summary method is static and uses this.

class Tray {
    private int seeds;
    public Tray(int seeds) {
        this.seeds = seeds;
    }
    public static int leftover() {
        return this.seeds;
    }
}

(a) Does leftover compile? Explain using this. (b) Rewrite leftover as an instance method that legally returns the field. (c) For Tray flat = new Tray(12); write a legal print call and the displayed value.

Question 5 of 5

Write a Beacon class with a private int watts. Include:

(a) a constructor Beacon(int watts) that uses this to store the parameter; (b) dim(int watts) that subtracts the parameter from the field using this; (c) ping(Tower t) that passes this to t.echo; (d) the displayed text after this caller, assuming Tower.echo prints the beacon power with a getter.

class Tower {
    public void echo(Beacon b) {
        System.out.print(b.power());
    }
}

Beacon ridge = new Beacon(40);
ridge.dim(7);
ridge.ping(new Tower());