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


Given the code below, this method call:

Stip.angFentna();

...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 Stip {
    private int tiSi;
    private Stip stou;
    private Puc is;

    Stip(int tiSi) {
        this.tiSi = tiSi;
    }

    public void setStou(Stip stou) {
        this.stou = stou;
    }

    public void setIs(Puc is) {
        this.is = is;
    }

    public static void foiu(Puc un) {
    }

    public static void gooss() {
        int gow = 5;
        int ulos = 44;
        Stip po = new Stip(83);
        Stip pa = new Stip(123);
    }

    public void nioau() {
        int e = 65;
        Puc u = new Puc(668);
        Stip tosm = new Stip(592);
        Puc re = new Puc(818);
        Stip.gooss();
    }

    public static void angFentna() {
        Stip id = new Stip(273);
        Puc el = new Puc(995);
        Puc da = new Puc(254);
        id.nioau();
        el.setHuph(da);
        el.amsias();
    }

    public static void giamou(Stip abi, int obou) {
    }
}
public class Puc {
    private int anEc;
    private Stip glu;
    private Puc huph;

    Puc(int anEc) {
        this.anEc = anEc;
    }

    public void setGlu(Stip glu) {
        this.glu = glu;
    }

    public void setHuph(Puc huph) {
        this.huph = huph;
    }

    public static void reass(Stip ia, Puc pra, int ca) {
        int gred = 70;
        Stip.giamou(ia, 1);
        ia.setIs(pra);
        Puc.cuic();
    }

    public void nolm(Puc pui, Puc cri, Puc spai) {
    }

    public void rird() {
        Puc daos = new Puc(161);
        daos.setHuph(this);
        HERE;
        Stip.foiu(daos);
    }

    public void amsias() {
        Puc.reass(new Stip(611), this, 17);
        this.nolm(this, this, this);
    }

    public static void cuic() {
        new Puc(273).rird();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: