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


Given the code below, this method call:

Veddi.cirbic();

...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 Veddi {
    private int ceki;
    private Mii ra;

    Veddi(int ceki) {
        this.ceki = ceki;
    }

    public void setRa(Mii ra) {
        this.ra = ra;
    }

    public static void cirbic() {
        Veddi.sangen(new Veddi(32), new Veddi(736));
        new Mii(738).necen();
    }

    public void treic(Mii es, Veddi pid) {
        int la = 25;
        HERE;
    }

    public static void sangen(Veddi iam, Veddi crio) {
        Mii id = new Mii(356);
        int meha = 75;
    }

    public void scri(Mii poch, Veddi is) {
        Veddi rege = new Veddi(956);
    }
}
public class Mii {
    private int cao;
    private Veddi hage;
    private Mii rer;

    Mii(int cao) {
        this.cao = cao;
    }

    public void setHage(Veddi hage) {
        this.hage = hage;
    }

    public void setRer(Mii rer) {
        this.rer = rer;
    }

    public void necen() {
        int ii = 52;
        Mii pha = new Mii(923);
        pha.oingsa(ii, this);
        this.setRer(pha);
        pha.irmpec(new Veddi(678));
    }

    public void irmpec(Veddi wi) {
        wi.setRa(this);
        wi.treic(this, new Veddi(154));
        wi.scri(this, wi);
    }

    public void oingsa(int uma, Mii ri) {
        Veddi ta = new Veddi(317);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: