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


Given the code below, this method call:

Baing.mefi();

...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 Baing {
    private int kism;
    private Oscro trul;

    Baing(int kism) {
        this.kism = kism;
    }

    public void setTrul(Oscro trul) {
        this.trul = trul;
    }

    public static void braon(int cas, int etro, int es) {
        HERE;
    }

    public static void mefi() {
        Baing chel = new Baing(321);
        Oscro i = new Oscro(690);
        Oscro di = new Oscro(582);
        i.setEr(chel);
        Oscro.opri();
        di.celPri(i, chel, di);
    }

    public static void stialo() {
        int li = 0;
    }

    public void phirle() {
        int to = 69;
        int sne = 97;
        int thi = 1;
    }
}
public class Oscro {
    private int beIr;
    private Baing hi;
    private Baing er;

    Oscro(int beIr) {
        this.beIr = beIr;
    }

    public void setHi(Baing hi) {
        this.hi = hi;
    }

    public void setEr(Baing er) {
        this.er = er;
    }

    public static void opri() {
        Oscro eck = new Oscro(113);
        int uss = 59;
        Baing ec = new Baing(524);
        int ka = 16;
        ec.phirle();
        eck.setHi(ec);
        Oscro.soni(ka);
    }

    public static void soni(int pa) {
        Baing.braon(pa, pa, pa);
        Baing.stialo();
    }

    public void celPri(Oscro houm, Baing muin, Oscro sesm) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: