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


Given the code below, this method call:

Bioie.cenpa();

...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 Bioie {
    private int esfi;
    private Heph pou;
    private Heph iaa;

    Bioie(int esfi) {
        this.esfi = esfi;
    }

    public void setPou(Heph pou) {
        this.pou = pou;
    }

    public void setIaa(Heph iaa) {
        this.iaa = iaa;
    }

    public void pero(int ar, Heph ee) {
        Heph nas = new Heph(484);
    }

    public static void cenpa() {
        new Heph(739).eited(new Bioie(408), new Bioie(960));
        Bioie.talol(79, new Bioie(459), 22);
        Bioie.orlust(8);
    }

    public static void orlust(int ong) {
        Heph.falPurd(ong);
    }

    public static void talol(int go, Bioie co, int u) {
        Heph deog = new Heph(374);
        Bioie roa = new Bioie(678);
        new Heph(742).spriss();
        co.setPou(deog);
        new Heph(9).fetria();
    }
}
public class Heph {
    private int diCe;
    private Heph pupo;
    private Bioie de;

    Heph(int diCe) {
        this.diCe = diCe;
    }

    public void setPupo(Heph pupo) {
        this.pupo = pupo;
    }

    public void setDe(Bioie de) {
        this.de = de;
    }

    public void fetria() {
        Heph aur = new Heph(850);
        Heph eod = new Heph(958);
        int a = 5;
        int nont = 54;
        eod.schar();
        eod.setPupo(this);
        eod.chel();
    }

    public void eited(Bioie he, Bioie es) {
        es.pero(18, new Heph(115));
    }

    public void salcim(int ibre, int ecil, int i) {
        int gnir = 36;
        HERE;
    }

    public static void falPurd(int ea) {
        int fi = 28;
    }

    public void spriss() {
        Bioie pe = new Bioie(191);
        int isou = 10;
        Heph ur = new Heph(720);
    }

    public void schar() {
        int prid = 82;
        int bu = 9;
        int te = 55;
    }

    public void chel() {
        int ospo = 75;
        int ha = 18;
        int ekbu = 16;
        this.salcim(ekbu, ha, 77);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: