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


Given the code below, this method call:

Kuc.wialt();

...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 Kuc {
    private int cosi;

    Kuc(int cosi) {
        this.cosi = cosi;
    }

    public static void gaas() {
        int malk = 54;
        int fluc = 32;
        int seil = 50;
        Kuc.hente();
    }

    public static void popea(Pra cael) {
        Kuc zas = new Kuc(664);
        Pra va = new Pra(595);
        cael.qeac(new Pra(893));
        Kuc.qauNechol(new Pra(482), zas);
    }

    public static void qauNechol(Pra prii, Kuc re) {
        Pra eeid = new Pra(133);
        int gac = 47;
        int ci = 88;
        eeid.setVize(prii);
        new Kuc(590).cerTriden(prii, ci, eeid);
    }

    public void cerTriden(Pra bil, int fasm, Pra vid) {
        int in = 90;
        bil.setRo(vid);
        Kuc.uilThas(in);
    }

    public static void hente() {
        int whe = 31;
        int ided = 62;
    }

    public static void jerur() {
        Pra et = new Pra(65);
        Kuc esno = new Kuc(227);
        int fo = 59;
        int po = 37;
    }

    public static void uilThas(int ba) {
        int damo = 22;
        int deou = 82;
        int uli = 52;
        HERE;
        Pra.venrel(uli, ba, 75);
    }

    public static void wialt() {
        new Pra(121).vitErmi(new Kuc(964));
        Kuc.popea(new Pra(796));
        Kuc.gaas();
    }
}
public class Pra {
    private int suVesgo;
    private Pra te;
    private Pra vize;
    private Pra ro;
    private Kuc op;

    Pra(int suVesgo) {
        this.suVesgo = suVesgo;
    }

    public void setTe(Pra te) {
        this.te = te;
    }

    public void setVize(Pra vize) {
        this.vize = vize;
    }

    public void setRo(Pra ro) {
        this.ro = ro;
    }

    public void setOp(Kuc op) {
        this.op = op;
    }

    public static void venrel(int susm, int ce, int hu) {
    }

    public void qeac(Pra nin) {
        Pra i = new Pra(205);
        int e = 8;
        Kuc iom = new Kuc(584);
    }

    public void vitErmi(Kuc pi) {
        Kuc poul = new Kuc(440);
        Kuc.jerur();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: