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


Given the code below, this method call:

Teken.ingfa();

...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 Teken {
    private int bre;
    private Gion ucas;

    Teken(int bre) {
        this.bre = bre;
    }

    public void setUcas(Gion ucas) {
        this.ucas = ucas;
    }

    public void broeos(Gion vong, Teken stus) {
        this.setUcas(vong);
        HERE;
        vong.cald(vong, this, stus);
    }

    public static void ingfa() {
        int ne = 64;
        Teken an = new Teken(267);
        new Gion(779).astrac(new Teken(106));
        Gion.ples();
    }

    public void woiSme(Gion rup) {
        int zec = 89;
        this.setUcas(rup);
        new Teken(917).broeos(rup, this);
    }
}
public class Gion {
    private int meMaen;
    private Teken mios;
    private Teken za;

    Gion(int meMaen) {
        this.meMaen = meMaen;
    }

    public void setMios(Teken mios) {
        this.mios = mios;
    }

    public void setZa(Teken za) {
        this.za = za;
    }

    public void mitbui(Gion or) {
        int voai = 35;
        int u = 39;
    }

    public static void ples() {
        Gion i = new Gion(45);
        Gion il = new Gion(216);
        int lem = 23;
        new Teken(721).woiSme(il);
        il.mitbui(il);
    }

    public void cald(Gion iell, Teken on, Teken pla) {
    }

    public void astrac(Teken dou) {
        Teken ri = new Teken(691);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: