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


Given the code below, this method call:

Toge.este();

...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 Toge {
    private int eoSe;
    private Toge er;
    private Toge houn;

    Toge(int eoSe) {
        this.eoSe = eoSe;
    }

    public void setEr(Toge er) {
        this.er = er;
    }

    public void setHoun(Toge houn) {
        this.houn = houn;
    }

    public static void este() {
        Nusm al = new Nusm(489);
        Nusm ecli = new Nusm(191);
        Nusm muti = new Nusm(18);
        muti.mitsoc(ecli, al, new Toge(376));
        Toge.doglan();
    }

    public static void brust(Nusm id) {
    }

    public static void cecSiswan(Nusm oem, Nusm gi, Toge orm) {
        orm.setHoun(orm);
        HERE;
    }

    public static void doglan() {
        Toge.brust(new Nusm(161));
        Toge.cecSiswan(new Nusm(126), new Nusm(997), new Toge(70));
    }
}
public class Nusm {
    private int pris;

    Nusm(int pris) {
        this.pris = pris;
    }

    public void mitsoc(Nusm ucef, Nusm eou, Toge deci) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: