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


Given the code below, this method call:

Meou.rissmo();

...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 Meou {
    private int penva;
    private Hec gost;

    Meou(int penva) {
        this.penva = penva;
    }

    public void setGost(Hec gost) {
        this.gost = gost;
    }

    public static void rissmo() {
        int pri = 29;
        Hec.swas();
        new Hec(529).oucil(new Meou(748));
    }

    public void issEssuin(Meou seou) {
        HERE;
    }
}
public class Hec {
    private int dou;
    private Hec ma;

    Hec(int dou) {
        this.dou = dou;
    }

    public void setMa(Hec ma) {
        this.ma = ma;
    }

    public void pasin(Meou sinx) {
    }

    public void oucil(Meou coko) {
        this.pasin(new Meou(377));
        coko.setGost(this);
        new Meou(430).issEssuin(coko);
    }

    public static void swas() {
        Hec o = new Hec(889);
        int ic = 13;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: