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


Given the code below, this method call:

Swir.noess();

...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 Swir {
    private int drure;

    Swir(int drure) {
        this.drure = drure;
    }

    public void besec(Swir on, Papha di) {
        di.setKa(this);
        HERE;
    }

    public static void noess() {
        Swir maip = new Swir(461);
        Swir.donirm();
        Papha.censic();
    }

    public static void donirm() {
        Swir pid = new Swir(454);
        Swir enri = new Swir(679);
        Swir ol = new Swir(720);
    }

    public void maeo(Swir pame) {
        int sesh = 94;
    }
}
public class Papha {
    private int onthi;
    private Swir stos;
    private Swir ka;

    Papha(int onthi) {
        this.onthi = onthi;
    }

    public void setStos(Swir stos) {
        this.stos = stos;
    }

    public void setKa(Swir ka) {
        this.ka = ka;
    }

    public static void censic() {
        Swir rarm = new Swir(831);
        new Swir(411).besec(rarm, new Papha(790));
        rarm.maeo(rarm);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: