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


Given the code below, this method call:

Houan.cameng();

...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 Houan {
    private int enId;
    private Sicu isi;

    Houan(int enId) {
        this.enId = enId;
    }

    public void setIsi(Sicu isi) {
        this.isi = isi;
    }

    public void dedfin(int ee, int cusm) {
    }

    public static void cameng() {
        int oisi = 62;
        new Houan(425).dedfin(oisi, 35);
        new Sicu(347).nacPhol(oisi, new Houan(681), oisi);
    }
}
public class Sicu {
    private int ocser;

    Sicu(int ocser) {
        this.ocser = ocser;
    }

    public void nacPhol(int sne, Houan foi, int ong) {
        foi.setIsi(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: