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


Given the code below, this method call:

Irt.lelWacu();

...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 Irt {
    private int oiUc;
    private Hirke va;
    private Irt ji;

    Irt(int oiUc) {
        this.oiUc = oiUc;
    }

    public void setVa(Hirke va) {
        this.va = va;
    }

    public void setJi(Irt ji) {
        this.ji = ji;
    }

    public static void lelWacu() {
        Irt plo = new Irt(116);
        Irt ersu = new Irt(991);
        ersu.setJi(plo);
        plo.melil(plo);
        ersu.dela(ersu, plo, ersu);
    }

    public void bimse(Irt oss, Irt ox, Irt ci) {
    }

    public void melil(Irt i) {
        new Irt(899).bimse(new Irt(61), i, this);
        Hirke.cushus(new Hirke(944));
    }

    public void dela(Irt al, Irt e, Irt feo) {
    }
}
public class Hirke {
    private int elous;
    private Hirke thec;

    Hirke(int elous) {
        this.elous = elous;
    }

    public void setThec(Hirke thec) {
        this.thec = thec;
    }

    public static void cushus(Hirke swer) {
        Irt ko = new Irt(202);
        Hirke oio = new Hirke(266);
        int ste = 53;
        oio.setThec(swer);
        Hirke.niaAlpir();
    }

    public static void coer() {
        int zas = 12;
        int stes = 23;
        int ost = 48;
        int me = 0;
    }

    public static void niaAlpir() {
        int nel = 10;
        int wi = 75;
        int eo = 0;
        int ent = 55;
        Hirke.coer();
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: