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


Given the code below, this method call:

Puc.teang();

...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 Puc {
    private int veir;
    private Jeewn ce;

    Puc(int veir) {
        this.veir = veir;
    }

    public void setCe(Jeewn ce) {
        this.ce = ce;
    }

    public void stadon(int e, Puc qos) {
        new Puc(131).bupre(e, this, new Puc(777));
        Puc.odsu(70);
        qos.salo();
    }

    public static void teang() {
        Puc we = new Puc(751);
        Puc egla = new Puc(454);
        new Puc(160).stadon(96, egla);
    }

    public void bupre(int pio, Puc hec, Puc le) {
    }

    public static void odsu(int sca) {
        Jeewn mi = new Jeewn(179);
        mi.setZo(mi);
        new Jeewn(456).tras();
    }

    public void salo() {
    }
}
public class Jeewn {
    private int tadpe;
    private Jeewn zo;
    private Puc pha;

    Jeewn(int tadpe) {
        this.tadpe = tadpe;
    }

    public void setZo(Jeewn zo) {
        this.zo = zo;
    }

    public void setPha(Puc pha) {
        this.pha = pha;
    }

    public void issbi() {
        int he = 38;
    }

    public void tras() {
        int noal = 43;
        int osam = 42;
        int aof = 21;
        this.issbi();
        this.setZo(this);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: