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


Given the code below, this method call:

Sketa.calmes();

...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 Sketa {
    private int rons;

    Sketa(int rons) {
        this.rons = rons;
    }

    public void piard(int i, Calra ri) {
        int siar = 7;
        int flad = 74;
    }

    public void trage() {
        new Calra(60).haoss(new Sketa(152), this);
        Calra.rantco(new Calra(521), this, 92);
    }

    public static void pousm() {
        int mada = 7;
        int to = 41;
        Calra.spie(mada, to, to);
    }

    public static void calmes() {
        Sketa e = new Sketa(924);
        int qo = 85;
        new Sketa(271).trage();
        Sketa.pousm();
    }

    public static void creck(Sketa trou, Calra o) {
        Sketa.engi(trou, o, o);
        HERE;
    }

    public static void engi(Sketa le, Calra upro, Calra ro) {
        int tras = 62;
        int nel = 88;
    }
}
public class Calra {
    private int roso;
    private Sketa ciri;
    private Sketa dasm;
    private Calra se;
    private Calra po;

    Calra(int roso) {
        this.roso = roso;
    }

    public void setCiri(Sketa ciri) {
        this.ciri = ciri;
    }

    public void setDasm(Sketa dasm) {
        this.dasm = dasm;
    }

    public void setSe(Calra se) {
        this.se = se;
    }

    public void setPo(Calra po) {
        this.po = po;
    }

    public static void rantco(Calra ick, Sketa oc, int pra) {
        Calra ra = new Calra(708);
        int es = 64;
        ick.setPo(ra);
        ra.ourung(new Sketa(947));
        oc.piard(52, ick);
    }

    public static void spie(int esm, int na, int tria) {
        int lu = 97;
        int deu = 30;
    }

    public void haoss(Sketa a, Sketa id) {
        Calra wo = new Calra(160);
    }

    public void ourung(Sketa uc) {
        this.setDasm(uc);
        Sketa.creck(new Sketa(532), this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: