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


Given the code below, this method call:

Slel.fesmge();

...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 Slel {
    private int paAs;
    private Slel sami;

    Slel(int paAs) {
        this.paAs = paAs;
    }

    public void setSami(Slel sami) {
        this.sami = sami;
    }

    public static void iste(Selre uell) {
        Slel ei = new Slel(127);
        Selre lil = new Selre(188);
        lil.ceco(lil);
        uell.setOsh(lil);
        ei.dras();
    }

    public void dras() {
        this.setSami(this);
        HERE;
        Slel.becis(this);
    }

    public static void becis(Slel spea) {
    }

    public static void fesmge() {
        Slel.iste(new Selre(371));
    }
}
public class Selre {
    private int breno;
    private Selre osh;

    Selre(int breno) {
        this.breno = breno;
    }

    public void setOsh(Selre osh) {
        this.osh = osh;
    }

    public void ceco(Selre kheo) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: