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


Given the code below, this method call:

Crod.fachon();

...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 Crod {
    private int ripo;

    Crod(int ripo) {
        this.ripo = ripo;
    }

    public static void fided() {
        int a = 89;
    }

    public static void mosh(Scha oga) {
        int esh = 4;
        HERE;
    }

    public static void fachon() {
        Crod mu = new Crod(470);
        Scha el = new Scha(864);
        el.setIr(mu);
        Crod.mosh(new Scha(64));
        Crod.fided();
    }
}
public class Scha {
    private int uidi;
    private Crod ir;

    Scha(int uidi) {
        this.uidi = uidi;
    }

    public void setIr(Crod ir) {
        this.ir = ir;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: