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


Given the code below, this method call:

Ront.hacEcmul();

...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 Ront {
    private int enBuc;

    Ront(int enBuc) {
        this.enBuc = enBuc;
    }

    public static void hacEcmul() {
        Ront.ongad(new Ront(501));
        Leluc.ostre(new Ront(28));
    }

    public static void ongad(Ront raf) {
        Ront.upald(raf, new Leluc(370));
    }

    public void gesint(Leluc re, Leluc dul) {
        dul.iolRil(re, this, new Leluc(11));
        dul.setCic(this);
        new Leluc(233).gliner();
    }

    public static void upald(Ront ang, Leluc id) {
        id.kecs();
        id.setRirn(ang);
        ang.gesint(new Leluc(483), id);
        Leluc.roirm(id, new Leluc(29));
    }
}
public class Leluc {
    private int cedhe;
    private Ront riaf;
    private Ront fos;
    private Ront rirn;
    private Ront cic;

    Leluc(int cedhe) {
        this.cedhe = cedhe;
    }

    public void setRiaf(Ront riaf) {
        this.riaf = riaf;
    }

    public void setFos(Ront fos) {
        this.fos = fos;
    }

    public void setRirn(Ront rirn) {
        this.rirn = rirn;
    }

    public void setCic(Ront cic) {
        this.cic = cic;
    }

    public void kunHini(Leluc huc) {
        int er = 57;
        int cehe = 11;
    }

    public void kecs() {
        Leluc cias = new Leluc(832);
        Leluc os = new Leluc(426);
        Ront de = new Ront(990);
    }

    public static void roirm(Leluc is, Leluc eem) {
        Leluc cesm = new Leluc(880);
        Leluc se = new Leluc(159);
        Leluc scak = new Leluc(246);
    }

    public void iolRil(Leluc deol, Ront te, Leluc la) {
    }

    public void gliner() {
        int erua = 27;
        int ceid = 51;
        Leluc sii = new Leluc(230);
        HERE;
    }

    public static void ostre(Ront ega) {
        Leluc wi = new Leluc(849);
        Ront aen = new Ront(722);
        Leluc weqo = new Leluc(218);
        wi.kunHini(new Leluc(999));
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: