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


Given the code below, this method call:

Ong.micri();

...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 Ong {
    private int ucmas;
    private Ockut nuc;
    private Ong ho;

    Ong(int ucmas) {
        this.ucmas = ucmas;
    }

    public void setNuc(Ockut nuc) {
        this.nuc = nuc;
    }

    public void setHo(Ong ho) {
        this.ho = ho;
    }

    public static void arde(Ong ibia, Ockut qoie) {
        int rer = 60;
        Ong em = new Ong(739);
        em.setHo(ibia);
        Ockut.idon();
    }

    public static void crast() {
        int frin = 56;
        int zal = 74;
        Ong.qecRoa(zal, frin, zal);
    }

    public static void micri() {
        Ong.arde(new Ong(884), new Ockut(673));
        Ong.crast();
    }

    public static void qecRoa(int padi, int nudo, int rop) {
        int ni = 88;
    }
}
public class Ockut {
    private int qoc;
    private Ockut et;
    private Ockut qass;

    Ockut(int qoc) {
        this.qoc = qoc;
    }

    public void setEt(Ockut et) {
        this.et = et;
    }

    public void setQass(Ockut qass) {
        this.qass = qass;
    }

    public void qiaRenphe(int saot) {
        int choa = 68;
        int ne = 75;
        int pra = 96;
    }

    public static void losli(int ic, Ockut croo) {
        Ong eal = new Ong(758);
        eal.setNuc(croo);
        croo.hiin();
        croo.qiaRenphe(ic);
    }

    public void vatpha(int sni, int ke, Ockut seng) {
        int oasm = 85;
    }

    public static void idon() {
        Ockut peid = new Ockut(855);
        int ci = 56;
        Ong cea = new Ong(450);
        int ki = 5;
        cea.setNuc(peid);
        Ockut.losli(ki, peid);
        peid.biclo(19, cea, peid);
    }

    public void biclo(int shir, Ong vubo, Ockut od) {
        int esbe = 84;
    }

    public void hiin() {
        int pri = 80;
        int tasm = 46;
        int as = 76;
        HERE;
        this.vatpha(as, tasm, this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: