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


Given the code below, this method call:

Esoc.udiist();

...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 Esoc {
    private int maUi;
    private Phied rism;
    private Esoc phe;
    private Phied muf;

    Esoc(int maUi) {
        this.maUi = maUi;
    }

    public void setRism(Phied rism) {
        this.rism = rism;
    }

    public void setPhe(Esoc phe) {
        this.phe = phe;
    }

    public void setMuf(Phied muf) {
        this.muf = muf;
    }

    public void moltne(Phied du) {
        int trai = 52;
        Esoc.poid(du, trai);
        du.setEcmi(this);
        Phied.wape(new Phied(460), du);
    }

    public void icip(Esoc aic, Phied meoc, Esoc mu) {
        Phied ea = new Phied(881);
    }

    public void nerthi(Phied cron, Phied ti, Esoc apir) {
        int sce = 24;
        this.icip(new Esoc(976), ti, apir);
        this.setRism(cron);
        apir.moltne(cron);
        apir.oirn(sce, cron, this);
    }

    public void oirn(int ceng, Phied ebin, Esoc hepi) {
    }

    public static void poid(Phied iw, int mep) {
        Esoc ces = new Esoc(909);
    }

    public static void udiist() {
        Phied.wukos(new Phied(656));
        new Esoc(761).nerthi(new Phied(527), new Phied(855), new Esoc(642));
    }

    public static void stac() {
        Phied urwa = new Phied(923);
        HERE;
    }
}
public class Phied {
    private int sico;
    private Esoc ecmi;

    Phied(int sico) {
        this.sico = sico;
    }

    public void setEcmi(Esoc ecmi) {
        this.ecmi = ecmi;
    }

    public static void wape(Phied brel, Phied wecs) {
        Esoc.stac();
    }

    public static void wukos(Phied sle) {
        Phied icos = new Phied(113);
        Esoc brus = new Esoc(157);
        Phied cel = new Phied(853);
        sle.whae(new Esoc(893), icos, sle);
    }

    public void whae(Esoc bri, Phied pio, Phied frio) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: