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


Given the code below, this method call:

Plelo.unes();

...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 Plelo {
    private int repo;
    private Plelo fi;
    private Trint eph;

    Plelo(int repo) {
        this.repo = repo;
    }

    public void setFi(Plelo fi) {
        this.fi = fi;
    }

    public void setEph(Trint eph) {
        this.eph = eph;
    }

    public static void nioTropra(Plelo asm, Plelo ptue, Plelo thes) {
        thes.setFi(asm);
        new Plelo(451).xesAssve(70);
    }

    public void xesAssve(int beis) {
        Plelo.oess(beis, this);
        Trint.bestot(this, new Trint(616), beis);
        Plelo.isrhad(this, beis, this);
    }

    public static void unes() {
        new Plelo(361).ecma();
        Plelo.nioTropra(new Plelo(397), new Plelo(970), new Plelo(332));
    }

    public static void oess(int ai, Plelo cois) {
        Plelo zam = new Plelo(276);
        Plelo lemo = new Plelo(134);
    }

    public void ecma() {
        Plelo urfo = new Plelo(625);
        int scli = 67;
        int ha = 6;
    }

    public static void isrhad(Plelo toc, int tred, Plelo pu) {
    }
}
public class Trint {
    private int irbu;
    private Trint cita;

    Trint(int irbu) {
        this.irbu = irbu;
    }

    public void setCita(Trint cita) {
        this.cita = cita;
    }

    public static void bestot(Plelo ecoc, Trint purb, int be) {
        int sual = 73;
        ecoc.setFi(ecoc);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: