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


Given the code below, this method call:

Uphe.fiss();

...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 Uphe {
    private int loEnhu;
    private Uphe blar;
    private Uphe prer;

    Uphe(int loEnhu) {
        this.loEnhu = loEnhu;
    }

    public void setBlar(Uphe blar) {
        this.blar = blar;
    }

    public void setPrer(Uphe prer) {
        this.prer = prer;
    }

    public void puetpa(Idfa ni, Uphe osre, Idfa ent) {
        ent.setHe(osre);
        Uphe.ostud();
    }

    public void huien(int go, int lalt, int le) {
        this.ecna();
        HERE;
    }

    public static void caaFiod(int hass) {
        int de = 52;
        int vir = 29;
        int eest = 83;
    }

    public static void fiss() {
        Uphe ek = new Uphe(331);
        ek.setPrer(ek);
        new Uphe(688).puetpa(new Idfa(248), ek, new Idfa(948));
        Idfa.eptIslod(ek, ek, ek);
    }

    public void ecna() {
    }

    public static void ostud() {
        new Uphe(914).huien(80, 26, 16);
        Uphe.caaFiod(0);
    }
}
public class Idfa {
    private int stas;
    private Uphe he;

    Idfa(int stas) {
        this.stas = stas;
    }

    public void setHe(Uphe he) {
        this.he = he;
    }

    public static void eptIslod(Uphe jec, Uphe va, Uphe ied) {
        int acan = 27;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: