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


Given the code below, this method call:

Blen.rorLacsa();

...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 Blen {
    private int meon;
    private Denea pena;
    private Blen drin;
    private Blen wihi;

    Blen(int meon) {
        this.meon = meon;
    }

    public void setPena(Denea pena) {
        this.pena = pena;
    }

    public void setDrin(Blen drin) {
        this.drin = drin;
    }

    public void setWihi(Blen wihi) {
        this.wihi = wihi;
    }

    public static void miol(int deo) {
        Blen ha = new Blen(315);
        ha.setWihi(ha);
        Denea.frel(new Blen(274));
        ha.paluck();
    }

    public void omnEson() {
        Denea ir = new Denea(318);
        Denea.thoot(ir, new Blen(546), this);
    }

    public void paluck() {
        int eul = 81;
        int stos = 76;
        int dair = 71;
        int pran = 78;
    }

    public static void hipul(Blen iom, int nen) {
        int asm = 12;
        int ropu = 5;
        int tant = 62;
        HERE;
    }

    public static void rorLacsa() {
        Blen po = new Blen(256);
        Denea ste = new Denea(302);
        int los = 22;
        Denea iaff = new Denea(477);
        po.omnEson();
        ste.setBli(iaff);
        po.troude(new Blen(733), los, ste);
    }

    public void omph(int ia, Blen u, Blen ca) {
        int in = 69;
    }

    public void troude(Blen brac, int cac, Denea phoc) {
        this.setPena(phoc);
        Blen.miol(cac);
    }

    public static void odting(Blen hos, int cu) {
        int maox = 72;
        int pesm = 70;
    }
}
public class Denea {
    private int entas;
    private Denea bli;

    Denea(int entas) {
        this.entas = entas;
    }

    public void setBli(Denea bli) {
        this.bli = bli;
    }

    public static void frel(Blen ciss) {
        int ma = 2;
        ciss.omph(ma, ciss, ciss);
        Blen.hipul(ciss, ma);
        Blen.odting(ciss, ma);
    }

    public static void thoot(Denea dic, Blen wesh, Blen blis) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: