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


Given the code below, this method call:

Scha.troun();

...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 Scha {
    private int usMolu;

    Scha(int usMolu) {
        this.usMolu = usMolu;
    }

    public static void troun() {
        Scha.snace(new Scha(507), new Bekur(968));
    }

    public static void cint(int atch, Scha fina) {
        Bekur atru = new Bekur(12);
        Bekur.namun(fina);
        HERE;
    }

    public static void snace(Scha ong, Bekur re) {
        int diiu = 18;
        re.setCi(ong);
        Scha.cint(diiu, ong);
        Bekur.chatu(ong, re, diiu);
    }
}
public class Bekur {
    private int teWiac;
    private Bekur ste;
    private Scha ci;

    Bekur(int teWiac) {
        this.teWiac = teWiac;
    }

    public void setSte(Bekur ste) {
        this.ste = ste;
    }

    public void setCi(Scha ci) {
        this.ci = ci;
    }

    public static void namun(Scha hism) {
        int icse = 56;
        Bekur an = new Bekur(317);
    }

    public static void chatu(Scha hosm, Bekur ewac, int ac) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: