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


Given the code below, this method call:

Skiou.nuaXissa();

...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 Skiou {
    private int sqa;
    private Epess eun;
    private Skiou toc;

    Skiou(int sqa) {
        this.sqa = sqa;
    }

    public void setEun(Epess eun) {
        this.eun = eun;
    }

    public void setToc(Skiou toc) {
        this.toc = toc;
    }

    public void graid() {
    }

    public static void nuaXissa() {
        Skiou.fraep(new Epess(884), new Skiou(655), new Skiou(155));
    }

    public static void fraep(Epess os, Skiou pa, Skiou huqa) {
        int al = 77;
        new Skiou(552).graid();
        os.setAat(huqa);
        os.ongEnspar(al, new Epess(379), os);
    }

    public static void pralra() {
        int spou = 80;
        int ha = 45;
        int o = 72;
        int cel = 66;
    }

    public static void fank(int ul) {
        int he = 63;
        int iss = 41;
    }
}
public class Epess {
    private int pei;
    private Skiou aat;

    Epess(int pei) {
        this.pei = pei;
    }

    public void setAat(Skiou aat) {
        this.aat = aat;
    }

    public static void blisse(Epess di, int feue, Epess dic) {
        int zi = 95;
        Skiou.fank(zi);
        HERE;
        Skiou.pralra();
    }

    public void ongEnspar(int mi, Epess imse, Epess cim) {
        Epess.blisse(new Epess(523), mi, this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: