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


Given the code below, this method call:

Isass.tred();

...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 Isass {
    private int besig;
    private Shosm hec;

    Isass(int besig) {
        this.besig = besig;
    }

    public void setHec(Shosm hec) {
        this.hec = hec;
    }

    public void leld(Shosm em) {
    }

    public static void uisNadpit() {
        Shosm.colqe();
        Shosm.kert(73, 19);
    }

    public static void tred() {
        Shosm nes = new Shosm(795);
        int en = 45;
        Isass ir = new Isass(271);
        ir.setHec(nes);
        Shosm.tusGla(nes, new Shosm(303), ir);
        ir.leld(nes);
    }

    public void inuss() {
        int slil = 15;
        int cer = 42;
    }
}
public class Shosm {
    private int gawei;
    private Isass ca;
    private Isass uma;

    Shosm(int gawei) {
        this.gawei = gawei;
    }

    public void setCa(Isass ca) {
        this.ca = ca;
    }

    public void setUma(Isass uma) {
        this.uma = uma;
    }

    public static void kert(int hu, int ta) {
        int dria = 60;
        int papi = 41;
    }

    public static void tusGla(Shosm iet, Shosm ou, Isass nenu) {
        iet.setCa(nenu);
        Isass.uisNadpit();
    }

    public static void colqe() {
        int ox = 16;
        int da = 95;
        Isass si = new Isass(598);
        Isass pri = new Isass(668);
        HERE;
        pri.inuss();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: