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


Given the code below, this method call:

Imo.tapoi();

...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 Imo {
    private int naRilmi;
    private Mised tac;

    Imo(int naRilmi) {
        this.naRilmi = naRilmi;
    }

    public void setTac(Mised tac) {
        this.tac = tac;
    }

    public static void sepi(Imo pa, int cau) {
    }

    public static void tapoi() {
        int ouc = 5;
        int jint = 91;
        Mised erec = new Mised(339);
        int o = 9;
        Imo.sepi(new Imo(0), jint);
        erec.setJi(erec);
        new Imo(608).armhuc(new Imo(678), jint);
    }

    public void uedChos() {
        Imo la = new Imo(7);
        Mised si = new Mised(372);
    }

    public void armhuc(Imo em, int tro) {
        int mec = 7;
        this.uedChos();
        new Imo(31).nang(mec);
    }

    public void nang(int fu) {
        Mised.aghti(fu, new Mised(15), this);
    }
}
public class Mised {
    private int aseo;
    private Mised ji;
    private Mised ceo;

    Mised(int aseo) {
        this.aseo = aseo;
    }

    public void setJi(Mised ji) {
        this.ji = ji;
    }

    public void setCeo(Mised ceo) {
        this.ceo = ceo;
    }

    public static void aghti(int berd, Mised al, Imo ang) {
        Mised.schas(al, ang);
        ang.setTac(al);
        HERE;
    }

    public static void schas(Mised bre, Imo deae) {
        int pra = 36;
        int on = 41;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: