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


Given the code below, this method call:

Crol.bace();

...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 Crol {
    private int qaMei;
    private Pacdi dris;

    Crol(int qaMei) {
        this.qaMei = qaMei;
    }

    public void setDris(Pacdi dris) {
        this.dris = dris;
    }

    public static void plid(Crol an, Crol ele) {
        int zeng = 61;
    }

    public static void ohaSes(Crol oplo, Crol niem, Pacdi lu) {
        Crol.plid(niem, new Crol(312));
        niem.setDris(lu);
        HERE;
    }

    public static void bace() {
        new Pacdi(153).opoPept();
        Crol.paber(new Crol(810), new Pacdi(943));
    }

    public static void paber(Crol ec, Pacdi aa) {
        ec.setDris(aa);
        Crol.ohaSes(ec, new Crol(739), aa);
    }
}
public class Pacdi {
    private int phui;
    private Pacdi ved;

    Pacdi(int phui) {
        this.phui = phui;
    }

    public void setVed(Pacdi ved) {
        this.ved = ved;
    }

    public void opoPept() {
        Crol pruc = new Crol(511);
        Crol fa = new Crol(12);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: