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


Given the code below, this method call:

Paci.ninEabem();

...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 Paci {
    private int bru;
    private Paci jes;
    private Siunt pra;

    Paci(int bru) {
        this.bru = bru;
    }

    public void setJes(Paci jes) {
        this.jes = jes;
    }

    public void setPra(Siunt pra) {
        this.pra = pra;
    }

    public static void ninEabem() {
        int os = 24;
        Siunt onch = new Siunt(731);
        int ga = 18;
        onch.setFue(onch);
        onch.maper(onch, ga, os);
        Siunt.isin(ga);
    }

    public void chaud(Siunt pe) {
        Siunt be = new Siunt(72);
        Siunt hirm = new Siunt(419);
    }
}
public class Siunt {
    private int bempu;
    private Siunt fue;

    Siunt(int bempu) {
        this.bempu = bempu;
    }

    public void setFue(Siunt fue) {
        this.fue = fue;
    }

    public void maper(Siunt veng, int rer, int plar) {
        this.setFue(this);
        veng.tiss();
    }

    public static void isin(int ples) {
    }

    public void cresm() {
        Siunt sto = new Siunt(672);
        int vujo = 1;
    }

    public void drer(Paci pla, Siunt olt) {
        int spis = 9;
        pla.chaud(olt);
        HERE;
    }

    public void tiss() {
        Siunt scra = new Siunt(48);
        new Siunt(516).drer(new Paci(412), scra);
        new Siunt(703).cresm();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: