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


Given the code below, this method call:

Ritin.dourpu();

...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 Ritin {
    private int esce;
    private Ritin dacs;

    Ritin(int esce) {
        this.esce = esce;
    }

    public void setDacs(Ritin dacs) {
        this.dacs = dacs;
    }

    public void cerpu(Ecic ak, int cle, Ritin re) {
        ak.setIcri(re);
        this.sellen(0);
        this.meol(ak, re);
    }

    public void meol(Ecic er, Ritin pism) {
        int isow = 92;
    }

    public void inle(int go, Ritin so) {
        so.setDacs(this);
        new Ritin(298).cerpu(new Ecic(160), 60, so);
        this.dend(go, so, this);
    }

    public static void dourpu() {
        Ecic irt = new Ecic(384);
        Ecic.fasa(irt, new Ecic(312));
        Ecic.trunwi(new Ecic(750));
    }

    public void sellen(int paed) {
        int ul = 37;
        HERE;
    }

    public void dend(int pem, Ritin arir, Ritin sti) {
    }
}
public class Ecic {
    private int ris;
    private Ritin ir;
    private Ritin icri;
    private Ritin su;

    Ecic(int ris) {
        this.ris = ris;
    }

    public void setIr(Ritin ir) {
        this.ir = ir;
    }

    public void setIcri(Ritin icri) {
        this.icri = icri;
    }

    public void setSu(Ritin su) {
        this.su = su;
    }

    public static void trunwi(Ecic dria) {
        int gir = 42;
        Ritin gi = new Ritin(657);
        dria.setIcri(gi);
        new Ritin(116).inle(gir, gi);
        dria.gass();
    }

    public static void fasa(Ecic cla, Ecic tiss) {
        Ecic croe = new Ecic(245);
        Ecic cim = new Ecic(218);
        cim.mepri(new Ecic(834), croe);
    }

    public void mepri(Ecic an, Ecic ke) {
        Ritin cuc = new Ritin(151);
    }

    public void gass() {
        int phed = 76;
        int bia = 57;
        int i = 28;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: