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


Given the code below, this method call:

Hepra.makPruba();

...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 Hepra {
    private int aish;
    private Hepra cac;

    Hepra(int aish) {
        this.aish = aish;
    }

    public void setCac(Hepra cac) {
        this.cac = cac;
    }

    public static void wekCimirk(Hepra ri) {
        Hepra neir = new Hepra(700);
        Atec el = new Atec(670);
        neir.setCac(ri);
        Hepra.isprub(new Hepra(796));
    }

    public static void isprub(Hepra ce) {
        Atec ond = new Atec(332);
        int plom = 45;
        ond.setOu(ond);
        Atec.koon();
        Hepra.phusm(ond, plom, ce);
    }

    public static void phusm(Atec ecre, int sor, Hepra haim) {
    }

    public static void makPruba() {
        int ec = 60;
        Hepra di = new Hepra(851);
        int freo = 91;
        di.setCac(di);
        Hepra.wekCimirk(new Hepra(886));
        Atec.eusm(ec, di, freo);
    }

    public static void mussin(int spre, int mioa, int mu) {
    }
}
public class Atec {
    private int cosis;
    private Atec ou;
    private Atec uass;
    private Atec dipi;

    Atec(int cosis) {
        this.cosis = cosis;
    }

    public void setOu(Atec ou) {
        this.ou = ou;
    }

    public void setUass(Atec uass) {
        this.uass = uass;
    }

    public void setDipi(Atec dipi) {
        this.dipi = dipi;
    }

    public static void eusm(int paec, Hepra tir, int swes) {
        int as = 88;
        Atec.prasm(as, paec, swes);
    }

    public static void hatas(int va) {
        int oir = 17;
        int isio = 96;
        int me = 75;
    }

    public static void prasm(int veua, int meon, int un) {
        int cin = 96;
    }

    public static void koon() {
        int irra = 77;
        int socs = 78;
        int pel = 94;
        Atec.hatas(socs);
        Atec.grird(pel);
    }

    public static void grird(int thu) {
        int mosm = 57;
        int onir = 24;
        int seon = 35;
        int biss = 7;
        HERE;
        Hepra.mussin(seon, 73, mosm);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: