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


Given the code below, this method call:

Proba.recis();

...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 Proba {
    private int gece;
    private Deng oid;

    Proba(int gece) {
        this.gece = gece;
    }

    public void setOid(Deng oid) {
        this.oid = oid;
    }

    public void flesum(int baid, Proba hoge) {
        int bif = 19;
        HERE;
    }

    public void inam() {
        int esm = 16;
        int thel = 18;
    }

    public static void recis() {
        new Deng(957).inpha(new Proba(773), 6);
        new Deng(528).sempia(new Proba(901));
    }

    public void ninang() {
        Proba ept = new Proba(933);
        Deng se = new Deng(604);
        int gliu = 56;
        this.inam();
        this.setOid(se);
        ept.flesum(gliu, this);
        Deng.dral(se, ept);
    }
}
public class Deng {
    private int ias;
    private Proba aese;
    private Proba co;

    Deng(int ias) {
        this.ias = ias;
    }

    public void setAese(Proba aese) {
        this.aese = aese;
    }

    public void setCo(Proba co) {
        this.co = co;
    }

    public void inpha(Proba oi, int oton) {
        Deng ci = new Deng(530);
    }

    public static void dral(Deng kesa, Proba i) {
    }

    public void sempia(Proba be) {
        be.setOid(this);
        new Proba(234).ninang();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: