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


Given the code below, this method call:

Bri.licAdmar();

...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 Bri {
    private int eseo;

    Bri(int eseo) {
        this.eseo = eseo;
    }

    public static void licAdmar() {
        Bia di = new Bia(46);
        new Bri(212).orpri(di);
    }

    public void orpri(Bia iwro) {
        Bri psao = new Bri(143);
        Bia.ceaOuzal(new Bri(378), iwro);
        iwro.crio();
    }

    public static void epre() {
        int ced = 36;
        int cec = 7;
    }
}
public class Bia {
    private int ingen;
    private Bri spi;
    private Bri keca;

    Bia(int ingen) {
        this.ingen = ingen;
    }

    public void setSpi(Bri spi) {
        this.spi = spi;
    }

    public void setKeca(Bri keca) {
        this.keca = keca;
    }

    public void crio() {
        Bri plin = new Bri(739);
        int fe = 63;
        this.setKeca(plin);
        HERE;
        Bri.epre();
    }

    public static void ceaOuzal(Bri erui, Bia eea) {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: