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


Given the code below, this method call:

Hodec.ociss();

...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 Hodec {
    private int pelef;
    private Hodec vig;

    Hodec(int pelef) {
        this.pelef = pelef;
    }

    public void setVig(Hodec vig) {
        this.vig = vig;
    }

    public static void ociss() {
        Hodec.plal(new Isen(852), new Hodec(347), new Isen(812));
    }

    public static void plal(Isen stec, Hodec siwu, Isen be) {
        stec.setOas(stec);
        be.eardso();
        be.slepa(be, stec);
    }
}
public class Isen {
    private int aess;
    private Isen oc;
    private Isen oas;

    Isen(int aess) {
        this.aess = aess;
    }

    public void setOc(Isen oc) {
        this.oc = oc;
    }

    public void setOas(Isen oas) {
        this.oas = oas;
    }

    public void qesto() {
        HERE;
        this.sloTaie();
    }

    public void slepa(Isen argi, Isen de) {
        int i = 88;
    }

    public void sloTaie() {
    }

    public void isnaw(Isen othi) {
        int tont = 58;
    }

    public void eardso() {
        Isen ge = new Isen(510);
        Isen ni = new Isen(740);
        int clu = 77;
        ge.setOas(this);
        ge.qesto();
        ge.isnaw(ge);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: