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


Given the code below, this method call:

Drau.tocPrer();

...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 Drau {
    private int udProk;
    private Pelse il;
    private Pelse dism;

    Drau(int udProk) {
        this.udProk = udProk;
    }

    public void setIl(Pelse il) {
        this.il = il;
    }

    public void setDism(Pelse dism) {
        this.dism = dism;
    }

    public void fekas(Drau eal, int wasi, Drau sene) {
        this.wamen();
    }

    public void stose(Drau el) {
    }

    public static void plirir() {
    }

    public void deca(int ur, Drau ha, Drau nin) {
    }

    public static void iscan() {
        Drau.plirir();
    }

    public void escal(int ven) {
        Drau wi = new Drau(173);
        this.stose(new Drau(911));
        new Drau(71).fekas(new Drau(799), ven, wi);
    }

    public void snol(int xa) {
    }

    public void wamen() {
        int cead = 10;
        HERE;
    }

    public static void tocPrer() {
        Drau pid = new Drau(467);
        Pelse ette = new Pelse(324);
        Drau.iscan();
        pid.setIl(ette);
        Pelse.pheTrocwo(pid);
    }
}
public class Pelse {
    private int traam;
    private Drau gric;
    private Drau somo;

    Pelse(int traam) {
        this.traam = traam;
    }

    public void setGric(Drau gric) {
        this.gric = gric;
    }

    public void setSomo(Drau somo) {
        this.somo = somo;
    }

    public static void pheTrocwo(Drau la) {
        int spe = 3;
        new Drau(769).snol(spe);
        new Drau(200).escal(spe);
        la.deca(spe, la, la);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: