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


Given the code below, this method call:

Pog.eahe();

...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 Pog {
    private int fePodes;
    private Trics buo;

    Pog(int fePodes) {
        this.fePodes = fePodes;
    }

    public void setBuo(Trics buo) {
        this.buo = buo;
    }

    public void trorer() {
        int soo = 28;
    }

    public static void padpua(Pog rur, Trics twu, Pog pren) {
    }

    public static void kidi(Trics vo, Pog dri) {
        Trics spe = new Trics(399);
        new Pog(757).trorer();
        dri.setBuo(vo);
        new Trics(43).dosm();
    }

    public static void eahe() {
        Pog.padpua(new Pog(196), new Trics(849), new Pog(3));
        Pog.kidi(new Trics(867), new Pog(512));
    }
}
public class Trics {
    private int pran;
    private Pog uern;

    Trics(int pran) {
        this.pran = pran;
    }

    public void setUern(Pog uern) {
        this.uern = uern;
    }

    public void dosm() {
        int luom = 97;
        int ulac = 15;
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: