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


Given the code below, this method call:

Cetch.ficOstcas();

...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 Cetch {
    private int naIs;
    private Cetch oel;

    Cetch(int naIs) {
        this.naIs = naIs;
    }

    public void setOel(Cetch oel) {
        this.oel = oel;
    }

    public void laqemn(Ebal ugre, Cetch a) {
        Ebal.padion();
        ugre.setOi(this);
        HERE;
        this.bilNian(ugre, new Ebal(448));
    }

    public void bilNian(Ebal cint, Ebal e) {
    }

    public static void ficOstcas() {
        int da = 59;
        int ka = 16;
        new Cetch(426).potic(da, new Cetch(547));
    }

    public void potic(int pe, Cetch acio) {
        this.setOel(acio);
        this.laqemn(new Ebal(684), acio);
    }
}
public class Ebal {
    private int pri;
    private Cetch oi;

    Ebal(int pri) {
        this.pri = pri;
    }

    public void setOi(Cetch oi) {
        this.oi = oi;
    }

    public static void padion() {
        Cetch ne = new Cetch(907);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: