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


Given the code below, this method call:

Ced.cecs();

...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 Ced {
    private int eju;
    private Ced eh;

    Ced(int eju) {
        this.eju = eju;
    }

    public void setEh(Ced eh) {
        this.eh = eh;
    }

    public void spen(Keng co, Keng he, Keng plal) {
    }

    public static void cecs() {
        int dast = 74;
        Keng kes = new Keng(203);
        kes.setEsos(kes);
        new Keng(699).miuRostot(kes);
        new Keng(372).cosclo();
    }
}
public class Keng {
    private int apRe;
    private Keng wo;
    private Keng esos;

    Keng(int apRe) {
        this.apRe = apRe;
    }

    public void setWo(Keng wo) {
        this.wo = wo;
    }

    public void setEsos(Keng esos) {
        this.esos = esos;
    }

    public void ouss(Keng ocec, Keng nen) {
        int bu = 26;
        HERE;
    }

    public void miuRostot(Keng ie) {
        ie.setEsos(this);
        this.issCaha();
        new Ced(669).spen(ie, this, new Keng(268));
    }

    public void issCaha() {
        Keng.pril();
        new Keng(213).ouss(new Keng(555), this);
    }

    public static void pril() {
        Ced mi = new Ced(165);
    }

    public void cosclo() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: