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


Given the code below, this method call:

Asmno.nepe();

...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 Asmno {
    private int lic;
    private Asmno wiha;
    private Asmno irn;
    private Glorm spo;
    private Asmno qano;

    Asmno(int lic) {
        this.lic = lic;
    }

    public void setWiha(Asmno wiha) {
        this.wiha = wiha;
    }

    public void setIrn(Asmno irn) {
        this.irn = irn;
    }

    public void setSpo(Glorm spo) {
        this.spo = spo;
    }

    public void setQano(Asmno qano) {
        this.qano = qano;
    }

    public void dioVoul(Asmno sce, int edba) {
        int mies = 58;
    }

    public static void pafi(Glorm doso, int heph, int truc) {
        int tiss = 5;
    }

    public static void nepe() {
        int fing = 37;
        Glorm peu = new Glorm(909);
        int snue = 99;
        int ioin = 51;
        Glorm sior = new Glorm(824);
        sior.ousHioste(peu);
    }

    public void iadmil(Asmno cic) {
        int apla = 47;
        int ardi = 80;
    }

    public static void driTemi() {
        int cuce = 13;
        int etam = 29;
        new Glorm(995).eoss();
    }
}
public class Glorm {
    private int umn;

    Glorm(int umn) {
        this.umn = umn;
    }

    public static void mecda(Glorm cas) {
        Glorm di = new Glorm(689);
    }

    public void ousHioste(Glorm pid) {
        Glorm.mecda(this);
        Asmno.driTemi();
    }

    public void eoss() {
        int whel = 28;
        Asmno arpe = new Asmno(114);
        Asmno rito = new Asmno(449);
        Asmno prit = new Asmno(156);
        rito.iadmil(rito);
        prit.setQano(arpe);
        this.pentuc();
        rito.dioVoul(arpe, whel);
    }

    public void pentuc() {
        int faft = 90;
        int ced = 84;
        int fu = 73;
        HERE;
        Asmno.pafi(this, fu, ced);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: