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


Given the code below, this method call:

Idla.zasIbe();

...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 Idla {
    private int ebVeka;
    private Idla aweb;
    private Piilf ic;
    private Idla ven;

    Idla(int ebVeka) {
        this.ebVeka = ebVeka;
    }

    public void setAweb(Idla aweb) {
        this.aweb = aweb;
    }

    public void setIc(Piilf ic) {
        this.ic = ic;
    }

    public void setVen(Idla ven) {
        this.ven = ven;
    }

    public static void zasIbe() {
        int urt = 86;
        Idla aran = new Idla(175);
        aran.setAweb(aran);
        aran.gossam(new Idla(780), urt);
    }

    public void gossam(Idla qir, int elfe) {
        Idla tus = new Idla(382);
        this.setAweb(tus);
        Idla.kerern();
    }

    public static void kerern() {
        Idla ap = new Idla(376);
        ap.setVen(ap);
        new Piilf(698).nouss();
        Piilf.jidasm(ap, ap);
    }
}
public class Piilf {
    private int dism;
    private Piilf nin;

    Piilf(int dism) {
        this.dism = dism;
    }

    public void setNin(Piilf nin) {
        this.nin = nin;
    }

    public void chrei() {
        int trir = 48;
        int gir = 75;
        int fos = 85;
        HERE;
        this.hucTeroc();
    }

    public void hucTeroc() {
        int sti = 99;
    }

    public void nouss() {
        Piilf plei = new Piilf(358);
        int osa = 89;
        Piilf.kotPhics();
        this.chrei();
        Piilf.dicInwhed(plei, this);
    }

    public static void dicInwhed(Piilf a, Piilf ucri) {
        int ma = 92;
        int frol = 84;
    }

    public static void jidasm(Idla nac, Idla pe) {
        int cas = 53;
        int ci = 22;
        int cin = 96;
    }

    public static void kotPhics() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: