Stack frames and objects (like the Idea Lab activity): Correct Solution


Given the code below, this method call:

Rhas.vadu();

...will eventually reach the point marked HERE. Draw a diagram of the stack and the heap at that point.

(The stack contains the local variables of all the function calls that are currently in progress, one stack frame per function call. The heap contains all of the objects that currently exist.)

In your diagram:

The code:

public class Rhas {
    private int rart;
    private Aau ve;
    private Rhas bia;
    private Aau se;

    Rhas(int rart) {
        this.rart = rart;
    }

    public void setVe(Aau ve) {
        this.ve = ve;
    }

    public void setBia(Rhas bia) {
        this.bia = bia;
    }

    public void setSe(Aau se) {
        this.se = se;
    }

    public static void wriss(Aau ror, Rhas el) {
        int sti = 4;
        HERE;
    }

    public static void vadu() {
        Aau.hecCosar(new Rhas(734), new Rhas(993));
        new Rhas(374).tarvan(new Aau(745));
        Aau.ceou(55, 40);
    }

    public void goised(Rhas haic, Aau hiwn) {
        Rhas eoss = new Rhas(805);
        eoss.acti();
        eoss.setSe(hiwn);
        Rhas.wriss(hiwn, eoss);
    }

    public void tarvan(Aau bru) {
        int so = 92;
        this.setBia(this);
        new Rhas(749).goised(new Rhas(800), bru);
    }

    public void acti() {
        int cel = 63;
    }
}
public class Aau {
    private int fel;

    Aau(int fel) {
        this.fel = fel;
    }

    public static void ceou(int du, int rias) {
        int aci = 47;
        int roft = 89;
    }

    public static void hecCosar(Rhas fuhi, Rhas ha) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: