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


Given the code below, this method call:

Trat.taoec();

...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 Trat {
    private int cics;
    private Aldo eas;
    private Aldo ce;
    private Aldo ni;

    Trat(int cics) {
        this.cics = cics;
    }

    public void setEas(Aldo eas) {
        this.eas = eas;
    }

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

    public void setNi(Aldo ni) {
        this.ni = ni;
    }

    public static void ochet() {
        int qan = 22;
        Aldo mo = new Aldo(930);
        Aldo dics = new Aldo(243);
        Aldo.feaAssoum(new Trat(618));
        dics.ciasu(new Trat(522));
    }

    public static void belpac() {
    }

    public static void taoec() {
        int to = 3;
        int es = 40;
        new Aldo(283).scise();
        Trat.ochet();
        Trat.belpac();
    }
}
public class Aldo {
    private int erNaud;

    Aldo(int erNaud) {
        this.erNaud = erNaud;
    }

    public void ciasu(Trat mabo) {
        Aldo fo = new Aldo(676);
        mabo.setCe(this);
        Aldo.baso(new Trat(861), 4);
    }

    public void scise() {
        Trat flad = new Trat(844);
        int qass = 21;
    }

    public static void baso(Trat trok, int al) {
        HERE;
    }

    public static void feaAssoum(Trat teru) {
        Trat poul = new Trat(139);
        Trat xods = new Trat(125);
        Trat keru = new Trat(618);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: