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


Given the code below, this method call:

Oran.moovil();

...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 Oran {
    private int danen;
    private Oran muro;
    private Cacse opac;

    Oran(int danen) {
        this.danen = danen;
    }

    public void setMuro(Oran muro) {
        this.muro = muro;
    }

    public void setOpac(Cacse opac) {
        this.opac = opac;
    }

    public static void moovil() {
        int ea = 88;
        int drin = 86;
        Oran anae = new Oran(849);
        Oran.acriss(ea);
    }

    public void tinwus(Oran ooss) {
        int mier = 96;
        Cacse.pabli();
        ooss.setMuro(this);
        HERE;
    }

    public static void acriss(int ec) {
        Cacse am = new Cacse(444);
        am.breett(new Oran(757));
        am.eumNoston(new Cacse(227), ec);
    }
}
public class Cacse {
    private int ded;
    private Oran rerd;

    Cacse(int ded) {
        this.ded = ded;
    }

    public void setRerd(Oran rerd) {
        this.rerd = rerd;
    }

    public static void aedBir(Cacse smar, int ehen) {
    }

    public void breett(Oran craa) {
        int lugh = 81;
        Oran twec = new Oran(45);
        twec.setOpac(this);
        twec.tinwus(craa);
        Cacse.aedBir(this, lugh);
    }

    public static void pabli() {
    }

    public void eumNoston(Cacse da, int vec) {
        int spel = 60;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: