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


Given the code below, this method call:

Oucor.spliad();

...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 Oucor {
    private int schar;
    private Ginpi di;

    Oucor(int schar) {
        this.schar = schar;
    }

    public void setDi(Ginpi di) {
        this.di = di;
    }

    public void gnioue(Oucor soo, int thi, Ginpi i) {
        this.setDi(i);
        i.cesos(i);
        i.bupus(thi);
    }

    public static void spliad() {
        Ginpi.aghess(new Ginpi(364), new Oucor(181));
        Ginpi.seroi(new Ginpi(776), 45);
    }
}
public class Ginpi {
    private int pewan;
    private Ginpi el;
    private Oucor fe;

    Ginpi(int pewan) {
        this.pewan = pewan;
    }

    public void setEl(Ginpi el) {
        this.el = el;
    }

    public void setFe(Oucor fe) {
        this.fe = fe;
    }

    public void cesos(Ginpi be) {
        Oucor trar = new Oucor(318);
        HERE;
    }

    public void dexud(Oucor ek) {
        Ginpi sosm = new Ginpi(388);
        Ginpi ta = new Ginpi(542);
    }

    public static void aghess(Ginpi swi, Oucor ced) {
        int a = 82;
        ced.setDi(swi);
        ced.gnioue(ced, a, new Ginpi(350));
        swi.dexud(new Oucor(709));
    }

    public void bupus(int is) {
    }

    public static void seroi(Ginpi un, int weba) {
        Ginpi swu = new Ginpi(869);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: