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


Given the code below, this method call:

Oilis.epoStush();

...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 Oilis {
    private int cic;
    private Baco grer;
    private Baco stei;

    Oilis(int cic) {
        this.cic = cic;
    }

    public void setGrer(Baco grer) {
        this.grer = grer;
    }

    public void setStei(Baco stei) {
        this.stei = stei;
    }

    public void esmCipal(int pid, Oilis et) {
        int ee = 15;
        this.piniu(pid);
    }

    public static void epoStush() {
        Baco asm = new Baco(564);
        int peci = 46;
        int mep = 93;
        Baco aun = new Baco(797);
        aun.hass();
        aun.setEc(asm);
        new Oilis(280).udmoic(new Oilis(845), peci);
    }

    public void edbe(Baco euc, Oilis ral, int pel) {
    }

    public void udmoic(Oilis bu, int u) {
        Baco ipan = new Baco(835);
        bu.setGrer(ipan);
        this.esmCipal(u, bu);
        this.edbe(ipan, this, u);
    }

    public void piniu(int hugi) {
        int os = 2;
        int vid = 10;
        HERE;
        Baco.prar(vid, os);
    }
}
public class Baco {
    private int vuFi;
    private Baco ec;

    Baco(int vuFi) {
        this.vuFi = vuFi;
    }

    public void setEc(Baco ec) {
        this.ec = ec;
    }

    public static void prar(int pasm, int qirm) {
        int pire = 88;
        int pa = 38;
    }

    public void hass() {
        Baco fiss = new Baco(745);
        int ic = 26;
        Baco lal = new Baco(776);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: