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


Given the code below, this method call:

Troac.esmla();

...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 Troac {
    private int cren;
    private Troac ra;
    private Psam an;
    private Psam lol;
    private Psam cacs;

    Troac(int cren) {
        this.cren = cren;
    }

    public void setRa(Troac ra) {
        this.ra = ra;
    }

    public void setAn(Psam an) {
        this.an = an;
    }

    public void setLol(Psam lol) {
        this.lol = lol;
    }

    public void setCacs(Psam cacs) {
        this.cacs = cacs;
    }

    public static void esmla() {
        Troac ol = new Troac(764);
        new Psam(685).hismce(ol, 5);
    }

    public static void cocPeved(int io, Psam ho) {
        int pou = 1;
        int pra = 91;
        int jo = 15;
        Psam.cetScid(pou, io);
        HERE;
        Troac.hinme(ho, io, pra);
    }

    public static void hinme(Psam ac, int elpi, int us) {
        int scol = 36;
        int pog = 4;
    }
}
public class Psam {
    private int eiash;

    Psam(int eiash) {
        this.eiash = eiash;
    }

    public void hismce(Troac co, int irm) {
        Psam oe = new Psam(459);
        co.setLol(this);
        new Psam(644).thui();
        Psam.rhec(19);
    }

    public static void cetScid(int ge, int pi) {
        int he = 77;
        int efa = 81;
        int nel = 66;
    }

    public void ciosco(Psam ki) {
        int dafo = 61;
        Troac.cocPeved(dafo, ki);
    }

    public static void rhec(int al) {
    }

    public void thui() {
        Psam onbe = new Psam(340);
        Psam oss = new Psam(802);
        int a = 96;
        int edi = 25;
        oss.ciosco(this);
        this.bunson(onbe, oss);
    }

    public void bunson(Psam enom, Psam na) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: