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


Given the code below, this method call:

Liu.kninpo();

...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 Liu {
    private int irCu;
    private Psass mi;

    Liu(int irCu) {
        this.irCu = irCu;
    }

    public void setMi(Psass mi) {
        this.mi = mi;
    }

    public void zemow(int groi) {
        int or = 36;
        this.fucIic();
    }

    public static void ehof() {
        int rur = 72;
        int istu = 22;
        int tert = 52;
        int pel = 23;
    }

    public static void kninpo() {
        Liu ca = new Liu(175);
        Psass aa = new Psass(440);
        int pe = 72;
        Liu ba = new Liu(63);
        int bepa = 90;
        ba.setMi(aa);
        Psass.fesDanken(pe);
        ca.zemow(pe);
    }

    public void wrar() {
        int di = 53;
        int co = 48;
    }

    public void fucIic() {
        int prew = 35;
        int cabe = 92;
    }
}
public class Psass {
    private int saen;
    private Psass ormo;
    private Liu esm;
    private Liu ste;

    Psass(int saen) {
        this.saen = saen;
    }

    public void setOrmo(Psass ormo) {
        this.ormo = ormo;
    }

    public void setEsm(Liu esm) {
        this.esm = esm;
    }

    public void setSte(Liu ste) {
        this.ste = ste;
    }

    public static void ouco() {
        Liu spil = new Liu(173);
        Psass.crabe(spil, spil);
        Psass.houdwa(spil, 55, 97);
    }

    public static void fesDanken(int okan) {
        int deel = 49;
        Liu ooca = new Liu(995);
        Liu edco = new Liu(724);
        Psass.ouco();
        Liu.ehof();
    }

    public static void houdwa(Liu ved, int oas, int afas) {
        int va = 77;
    }

    public static void crabe(Liu ie, Liu wi) {
        Psass.teoMiau(wi);
        ie.wrar();
    }

    public static void teoMiau(Liu esri) {
        int tre = 58;
        int ciec = 10;
        int be = 29;
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: