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


Given the code below, this method call:

Eush.biap();

...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 Eush {
    private int nen;
    private Pinti appi;
    private Eush ost;

    Eush(int nen) {
        this.nen = nen;
    }

    public void setAppi(Pinti appi) {
        this.appi = appi;
    }

    public void setOst(Eush ost) {
        this.ost = ost;
    }

    public static void biap() {
        Eush sirn = new Eush(406);
        new Eush(323).irph();
        sirn.setOst(sirn);
        new Eush(613).cliler(new Eush(21));
        sirn.broi(sirn, sirn);
    }

    public void irph() {
        int roag = 86;
        Eush.zeass(this);
    }

    public static void ving(Eush phoc, Pinti cuc) {
        Eush oss = new Eush(806);
        int er = 2;
    }

    public void innul() {
        Pinti id = new Pinti(748);
        Pinti.kirdim();
    }

    public static void zeass(Eush ma) {
        Pinti ic = new Pinti(133);
        int elfi = 71;
        Pinti sird = new Pinti(853);
        int ha = 24;
    }

    public void cliler(Eush zes) {
        int io = 19;
        this.setOst(zes);
        new Pinti(437).tril(new Eush(665), this);
    }

    public void peha(Eush asil) {
    }

    public void broi(Eush sik, Eush upa) {
        this.peha(sik);
    }
}
public class Pinti {
    private int arJioco;
    private Pinti occo;
    private Pinti ces;

    Pinti(int arJioco) {
        this.arJioco = arJioco;
    }

    public void setOcco(Pinti occo) {
        this.occo = occo;
    }

    public void setCes(Pinti ces) {
        this.ces = ces;
    }

    public static void vessa() {
        int uss = 0;
    }

    public void tril(Eush omb, Eush sece) {
        int gi = 85;
        Eush.ving(omb, this);
        this.setOcco(this);
        sece.innul();
    }

    public static void kirdim() {
        int o = 59;
        int riat = 22;
        int ra = 76;
        int hu = 46;
        Pinti.vessa();
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: