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


Given the code below, this method call:

Tross.budtef();

...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 Tross {
    private int ciTapoi;
    private Tross ha;
    private Tross eddi;
    private Tross id;

    Tross(int ciTapoi) {
        this.ciTapoi = ciTapoi;
    }

    public void setHa(Tross ha) {
        this.ha = ha;
    }

    public void setEddi(Tross eddi) {
        this.eddi = eddi;
    }

    public void setId(Tross id) {
        this.id = id;
    }

    public static void urun(int chos, int er, int or) {
    }

    public static void coprir() {
        int ihe = 33;
        int buo = 55;
        int caip = 71;
        int va = 43;
        Tross.urun(ihe, buo, caip);
        HERE;
    }

    public static void budtef() {
        Adbes.flaVanca(new Tross(66), new Adbes(821), new Tross(872));
        Adbes.aduoun(new Adbes(354), new Adbes(552));
        Adbes.crebin(54);
    }
}
public class Adbes {
    private int uss;

    Adbes(int uss) {
        this.uss = uss;
    }

    public static void jesta(Adbes u) {
        int camo = 63;
        Tross merm = new Tross(779);
        int re = 44;
        merm.setId(merm);
        Tross.coprir();
    }

    public static void crebin(int bopu) {
        int ve = 62;
        int glac = 98;
        int es = 22;
    }

    public static void aduoun(Adbes pran, Adbes grel) {
        Tross flen = new Tross(304);
        Adbes e = new Adbes(615);
        Adbes.jesta(e);
    }

    public static void flaVanca(Tross go, Adbes sixe, Tross dend) {
        Adbes ang = new Adbes(932);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: