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


Given the code below, this method call:

Lapac.menern();

...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 Lapac {
    private int cassi;
    private Lapac mu;

    Lapac(int cassi) {
        this.cassi = cassi;
    }

    public void setMu(Lapac mu) {
        this.mu = mu;
    }

    public void inge(Lapac cio) {
        Seng.vuala();
        this.setMu(cio);
        HERE;
    }

    public static void menern() {
        Seng spe = new Seng(466);
        new Lapac(323).inge(new Lapac(899));
    }
}
public class Seng {
    private int uct;

    Seng(int uct) {
        this.uct = uct;
    }

    public static void vuala() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: