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


Given the code below, this method call:

Urm.precu();

...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 sund;
    private Mesm pa;

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

    public void setPa(Mesm pa) {
        this.pa = pa;
    }

    public void pahell(Urm fep, Mesm o) {
        Mesm.blecur(o, fep, this);
        this.setPa(o);
        HERE;
    }

    public static void precu() {
        int tren = 12;
        Mesm wiom = new Mesm(753);
        new Urm(315).pahell(new Urm(421), wiom);
    }
}
public class Mesm {
    private int cous;

    Mesm(int cous) {
        this.cous = cous;
    }

    public static void blecur(Mesm is, Urm uno, Urm es) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: