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


Given the code below, this method call:

Cinid.hopunt();

...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 Cinid {
    private int knido;

    Cinid(int knido) {
        this.knido = knido;
    }

    public static void icia(int peur, int oci, Duouc ra) {
        HERE;
    }

    public static void ploRiur(Cinid niro, Cinid ti, Cinid zi) {
    }

    public static void hopunt() {
        Cinid.ploRiur(new Cinid(927), new Cinid(691), new Cinid(78));
        new Duouc(491).cirt(new Cinid(203), new Duouc(533));
    }
}
public class Duouc {
    private int deng;
    private Cinid va;
    private Duouc li;
    private Cinid uin;

    Duouc(int deng) {
        this.deng = deng;
    }

    public void setVa(Cinid va) {
        this.va = va;
    }

    public void setLi(Duouc li) {
        this.li = li;
    }

    public void setUin(Cinid uin) {
        this.uin = uin;
    }

    public void cirt(Cinid qos, Duouc idhe) {
        Duouc pagu = new Duouc(873);
        pagu.setLi(idhe);
        new Duouc(551).breSeble(idhe);
        Duouc.rarSqung();
    }

    public void breSeble(Duouc deha) {
        int ris = 13;
        int pra = 82;
        this.flol(deha);
        deha.setLi(this);
        Cinid.icia(pra, ris, deha);
    }

    public static void rarSqung() {
    }

    public void flol(Duouc usel) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: