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


Given the code below, this method call:

Hinca.drolne();

...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 Hinca {
    private int onti;
    private Gua en;
    private Gua agus;

    Hinca(int onti) {
        this.onti = onti;
    }

    public void setEn(Gua en) {
        this.en = en;
    }

    public void setAgus(Gua agus) {
        this.agus = agus;
    }

    public void hars() {
        Hinca.painth(this, new Hinca(253));
        Hinca.irtSteck(new Gua(979), this);
        Gua.imeSauc();
    }

    public static void painth(Hinca mond, Hinca esno) {
        int olce = 54;
        int heji = 90;
    }

    public static void drolne() {
        Gua coac = new Gua(685);
        Hinca sa = new Hinca(565);
        Hinca swen = new Hinca(184);
        new Gua(890).awnvee(coac, sa, swen);
        coac.setUi(sa);
        sa.hars();
    }

    public void iescen() {
        Gua nal = new Gua(490);
        int rer = 6;
        int essu = 81;
        HERE;
    }

    public static void irtSteck(Gua plal, Hinca zele) {
        int ar = 8;
        plal.setUi(zele);
        zele.iescen();
    }
}
public class Gua {
    private int mirch;
    private Hinca ui;

    Gua(int mirch) {
        this.mirch = mirch;
    }

    public void setUi(Hinca ui) {
        this.ui = ui;
    }

    public static void imeSauc() {
        int epe = 86;
        int fo = 99;
    }

    public void awnvee(Gua er, Hinca li, Hinca su) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: