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


Given the code below, this method call:

Ced.iweIsio();

...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 Ced {
    private int munil;
    private Ced tac;
    private Bem ii;

    Ced(int munil) {
        this.munil = munil;
    }

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

    public void setIi(Bem ii) {
        this.ii = ii;
    }

    public void lengoc() {
        int ple = 41;
        int pel = 61;
        Ced.ossBia(ple);
        Bem.ongEpeu(pel);
    }

    public static void iweIsio() {
        Bem ce = new Bem(505);
        Bem e = new Bem(61);
        Ced il = new Ced(654);
        ce.setBre(e);
        Ced.rocel();
    }

    public void ingu(Ced sas, int po) {
        int cosm = 52;
    }

    public static void ossBia(int hi) {
        int ror = 50;
        Ced.erpric(hi, ror, hi);
        HERE;
    }

    public static void erpric(int meeu, int du, int o) {
    }

    public static void rocel() {
        int phe = 74;
        Ced cer = new Ced(423);
        Bem lero = new Bem(447);
        cer.setTac(cer);
        cer.lengoc();
        cer.ingu(cer, phe);
    }
}
public class Bem {
    private int ocLuei;
    private Bem bre;

    Bem(int ocLuei) {
        this.ocLuei = ocLuei;
    }

    public void setBre(Bem bre) {
        this.bre = bre;
    }

    public static void ongEpeu(int taor) {
        int ent = 38;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: