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


Given the code below, this method call:

Hitid.eciZuck();

...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 Hitid {
    private int odChuam;

    Hitid(int odChuam) {
        this.odChuam = odChuam;
    }

    public void almo(Iamo esut, Hitid ei, int sa) {
        esut.setOsor(this);
        HERE;
    }

    public static void eciZuck() {
        int gi = 27;
        Hitid o = new Hitid(192);
        Iamo.ticed(new Iamo(27));
        o.almo(new Iamo(150), o, gi);
    }
}
public class Iamo {
    private int olTriot;
    private Hitid osor;

    Iamo(int olTriot) {
        this.olTriot = olTriot;
    }

    public void setOsor(Hitid osor) {
        this.osor = osor;
    }

    public static void ticed(Iamo phun) {
        Iamo as = new Iamo(643);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: