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


Given the code below, this method call:

Iss.pebo();

...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 Iss {
    private int sont;
    private Creic ut;
    private Creic pa;

    Iss(int sont) {
        this.sont = sont;
    }

    public void setUt(Creic ut) {
        this.ut = ut;
    }

    public void setPa(Creic pa) {
        this.pa = pa;
    }

    public static void sluci(int iqel) {
        Creic.pousac(iqel);
        HERE;
    }

    public void geng() {
        int no = 48;
        int ri = 91;
        Creic lus = new Creic(534);
        lus.setLel(this);
        Creic.spiAees(no);
    }

    public static void ossClict() {
        int scoa = 22;
        int sifa = 46;
    }

    public static void iseasm(int fiap) {
        int pioi = 0;
        Iss.ossClict();
        Iss.sluci(fiap);
    }

    public static void pebo() {
        Iss oran = new Iss(215);
        Creic ou = new Creic(333);
        Creic ci = new Creic(786);
        Creic lema = new Creic(411);
        oran.setPa(ci);
        oran.geng();
    }
}
public class Creic {
    private int idgil;
    private Iss lel;
    private Creic iri;

    Creic(int idgil) {
        this.idgil = idgil;
    }

    public void setLel(Iss lel) {
        this.lel = lel;
    }

    public void setIri(Creic iri) {
        this.iri = iri;
    }

    public static void pousac(int cied) {
        int ec = 7;
    }

    public void fenbil() {
        int ha = 9;
        int pras = 74;
        int si = 62;
        int ca = 59;
    }

    public void fiesti() {
        int po = 6;
        int ad = 54;
        int el = 41;
        int fued = 60;
    }

    public static void spiAees(int cioc) {
        Creic se = new Creic(638);
        int osit = 22;
        se.fenbil();
        Iss.iseasm(osit);
        se.fiesti();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: