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


Given the code below, this method call:

Pra.thueng();

...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 Pra {
    private int tebo;
    private Tapo po;

    Pra(int tebo) {
        this.tebo = tebo;
    }

    public void setPo(Tapo po) {
        this.po = po;
    }

    public void xeal(Tapo id, Pra ihio, Tapo il) {
    }

    public static void priHecum() {
        int naes = 34;
        int qes = 78;
    }

    public static void thueng() {
        Tapo cer = new Tapo(347);
        Pra edki = new Pra(833);
        Tapo ou = new Tapo(203);
        cer.setDa(edki);
        edki.voist();
    }

    public void voist() {
        Tapo e = new Tapo(708);
        this.setPo(e);
        new Tapo(579).neless(e, this);
        this.xeal(e, this, e);
    }

    public static void isdir() {
        int es = 84;
        int mefi = 43;
        int ar = 44;
        int scor = 30;
        HERE;
        Pra.priHecum();
    }
}
public class Tapo {
    private int doio;
    private Tapo niat;
    private Pra da;

    Tapo(int doio) {
        this.doio = doio;
    }

    public void setNiat(Tapo niat) {
        this.niat = niat;
    }

    public void setDa(Pra da) {
        this.da = da;
    }

    public void copler(Tapo vopi, Tapo mii, Pra pese) {
    }

    public void neless(Tapo viun, Pra be) {
        Pra.isdir();
        this.copler(this, viun, be);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: