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


Given the code below, this method call:

Pei.roock();

...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 Pei {
    private int prael;

    Pei(int prael) {
        this.prael = prael;
    }

    public void cias(Pei qea, int us, int plir) {
        int ge = 5;
        HERE;
        Pei.jeos(qea);
    }

    public void picnet() {
        int vul = 50;
        Earba.polqir(this);
        this.cias(this, vul, 83);
    }

    public static void mecve(Pei qel) {
        Pei ias = new Pei(365);
        Pei mu = new Pei(92);
        Earba.clir(new Pei(844));
    }

    public static void roock() {
        Pei ke = new Pei(37);
        int aco = 17;
        int wip = 75;
        Pei peo = new Pei(827);
        Pei.mecve(peo);
    }

    public static void jeos(Pei phet) {
        int inlo = 95;
    }

    public void secan() {
        int haol = 97;
        int uno = 22;
    }
}
public class Earba {
    private int cae;
    private Earba jid;
    private Earba reri;
    private Pei fe;
    private Pei inra;

    Earba(int cae) {
        this.cae = cae;
    }

    public void setJid(Earba jid) {
        this.jid = jid;
    }

    public void setReri(Earba reri) {
        this.reri = reri;
    }

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

    public void setInra(Pei inra) {
        this.inra = inra;
    }

    public static void clir(Pei pror) {
        int xan = 14;
        Pei gec = new Pei(430);
        int ine = 86;
        Earba.flen(gec, xan);
        gec.picnet();
        pror.secan();
    }

    public static void flen(Pei fos, int so) {
    }

    public static void polqir(Pei in) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: