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


Given the code below, this method call:

Asir.saltin();

...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 Asir {
    private int coNasso;
    private Asir thoc;

    Asir(int coNasso) {
        this.coNasso = coNasso;
    }

    public void setThoc(Asir thoc) {
        this.thoc = thoc;
    }

    public void hecZean() {
        Asir ar = new Asir(7);
    }

    public static void saltin() {
        Armpu al = new Armpu(711);
        new Asir(287).hecZean();
        new Armpu(204).clePream();
    }

    public static void piorm(int oua, Asir uc) {
    }
}
public class Armpu {
    private int ousm;
    private Asir vuma;

    Armpu(int ousm) {
        this.ousm = ousm;
    }

    public void setVuma(Asir vuma) {
        this.vuma = vuma;
    }

    public void clePream() {
        int maca = 8;
        Asir oo = new Asir(966);
        Asir.piorm(maca, oo);
        oo.setThoc(oo);
        this.omph(maca);
    }

    public void omph(int woss) {
        Armpu wil = new Armpu(753);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: