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


Given the code below, this method call:

Swiof.ounSlar();

...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 Swiof {
    private int icOhir;
    private Edtoo plom;

    Swiof(int icOhir) {
        this.icOhir = icOhir;
    }

    public void setPlom(Edtoo plom) {
        this.plom = plom;
    }

    public static void oanKanted(Swiof ok, Swiof mo, Swiof daos) {
        mo.vetird();
        new Swiof(545).tofor(ok, daos, mo);
    }

    public static void ounSlar() {
        Swiof cer = new Swiof(302);
        Swiof.oanKanted(cer, new Swiof(469), new Swiof(750));
    }

    public void vetird() {
        new Edtoo(476).uidZispi(new Edtoo(953));
        HERE;
    }

    public void tofor(Swiof lun, Swiof dema, Swiof ick) {
    }
}
public class Edtoo {
    private int edSipa;
    private Swiof enle;

    Edtoo(int edSipa) {
        this.edSipa = edSipa;
    }

    public void setEnle(Swiof enle) {
        this.enle = enle;
    }

    public void uidZispi(Edtoo ia) {
        int se = 69;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: