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


Given the code below, this method call:

Ioght.isda();

...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 Ioght {
    private int splic;

    Ioght(int splic) {
        this.splic = splic;
    }

    public static void lemZewl() {
        int ad = 83;
        int deat = 63;
        int rehi = 94;
        int jebe = 72;
        int alil = 57;
    }

    public void gucur(Depac sa) {
        int dosh = 6;
        int bris = 34;
        sa.setSor(sa);
        Depac.ambi(sa, this);
    }

    public void lesa(Depac ro) {
        Ioght zuss = new Ioght(902);
        Depac.sprass(ro, 92);
    }

    public static void peper() {
        int mism = 18;
        int u = 6;
        int psa = 4;
        HERE;
    }

    public static void isda() {
        Depac saer = new Depac(1);
        Ioght mie = new Ioght(178);
        Ioght plec = new Ioght(549);
        Ioght uest = new Ioght(729);
        uest.lesa(saer);
        new Ioght(438).gucur(new Depac(953));
        uest.fitril();
    }

    public static void scoSidsno(int od, Depac po) {
        int fo = 26;
        int rir = 63;
        int phad = 16;
    }

    public void fitril() {
        int ror = 49;
        int roat = 55;
        int etec = 44;
        Ioght.lemZewl();
    }
}
public class Depac {
    private int elrir;
    private Ioght to;
    private Ioght coet;
    private Depac sor;
    private Depac ca;

    Depac(int elrir) {
        this.elrir = elrir;
    }

    public void setTo(Ioght to) {
        this.to = to;
    }

    public void setCoet(Ioght coet) {
        this.coet = coet;
    }

    public void setSor(Depac sor) {
        this.sor = sor;
    }

    public void setCa(Depac ca) {
        this.ca = ca;
    }

    public void niec(Ioght flud, int irm) {
        int cind = 84;
        this.sucEde(this);
        Ioght.peper();
    }

    public static void ambi(Depac acir, Ioght aom) {
        int iapa = 22;
        Ioght.scoSidsno(iapa, acir);
        acir.niec(aom, iapa);
    }

    public static void sprass(Depac iar, int eout) {
        Depac eeo = new Depac(961);
    }

    public void sucEde(Depac sas) {
        int hase = 27;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: