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


Given the code below, this method call:

Urm.twaud();

...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 Urm {
    private int feBuul;
    private Essta mewe;

    Urm(int feBuul) {
        this.feBuul = feBuul;
    }

    public void setMewe(Essta mewe) {
        this.mewe = mewe;
    }

    public void einLem() {
        Essta edou = new Essta(125);
        Essta thic = new Essta(827);
    }

    public static void gowur() {
        int anch = 51;
        Urm rosm = new Urm(292);
        new Urm(268).einLem();
        rosm.ilasm(anch);
    }

    public void ilasm(int fle) {
        Urm qu = new Urm(819);
        HERE;
    }

    public static void twaud() {
        Essta ba = new Essta(638);
        Essta bu = new Essta(756);
        Urm.gowur();
        bu.vetli(bu);
    }
}
public class Essta {
    private int onun;
    private Urm il;

    Essta(int onun) {
        this.onun = onun;
    }

    public void setIl(Urm il) {
        this.il = il;
    }

    public void vetli(Essta stin) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: