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


Given the code below, this method call:

Giodi.genron();

...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 Giodi {
    private int dirpo;
    private Plosk ces;
    private Giodi pec;
    private Plosk isum;

    Giodi(int dirpo) {
        this.dirpo = dirpo;
    }

    public void setCes(Plosk ces) {
        this.ces = ces;
    }

    public void setPec(Giodi pec) {
        this.pec = pec;
    }

    public void setIsum(Plosk isum) {
        this.isum = isum;
    }

    public void iant(int noti, Plosk bri, int ecid) {
        int ploe = 3;
        this.setCes(bri);
        new Plosk(90).umes(ploe, bri, new Plosk(808));
    }

    public static void bruLeltwo(Plosk eiha, Plosk mori) {
        int fe = 14;
        int ju = 28;
        int heci = 88;
        mori.sqelo(eiha);
        HERE;
        Giodi.nagen(fe);
    }

    public static void genron() {
        Plosk crel = new Plosk(677);
        int loec = 17;
        int brel = 89;
        crel.setEul(crel);
        new Giodi(312).iant(loec, crel, brel);
        crel.stiPasoss(crel);
    }

    public static void nagen(int doi) {
        int cuc = 16;
    }
}
public class Plosk {
    private int holca;
    private Plosk eul;

    Plosk(int holca) {
        this.holca = holca;
    }

    public void setEul(Plosk eul) {
        this.eul = eul;
    }

    public void rorTep() {
    }

    public void sqelo(Plosk vope) {
    }

    public static void rekud(Plosk psun, int tus) {
    }

    public void oooFarsen() {
        int jif = 29;
        Giodi.bruLeltwo(this, new Plosk(576));
    }

    public void stiPasoss(Plosk ous) {
        int qo = 79;
        int edpo = 74;
        int cau = 96;
        ous.rorTep();
    }

    public void umes(int ilic, Plosk seda, Plosk wu) {
        seda.setEul(this);
        new Plosk(245).oooFarsen();
        Plosk.rekud(wu, ilic);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: