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


Given the code below, this method call:

Benof.rass();

...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 Benof {
    private int uspe;
    private Loni va;
    private Benof wo;

    Benof(int uspe) {
        this.uspe = uspe;
    }

    public void setVa(Loni va) {
        this.va = va;
    }

    public void setWo(Benof wo) {
        this.wo = wo;
    }

    public void coolk(Loni mi) {
        int od = 66;
    }

    public void chir() {
        int ooc = 25;
        int asm = 57;
        HERE;
    }

    public static void rass() {
        Loni pid = new Loni(653);
        Loni hec = new Loni(860);
        new Loni(689).blos();
        Benof.orbe(hec);
    }

    public static void orbe(Loni ple) {
        int tac = 50;
    }

    public void iaaPhash() {
        int muel = 69;
        int ris = 59;
        int ses = 4;
    }

    public static void pijur(Loni pse, Benof mu) {
        int lon = 97;
        mu.setVa(pse);
        mu.chir();
    }
}
public class Loni {
    private int ucFegh;
    private Benof ho;

    Loni(int ucFegh) {
        this.ucFegh = ucFegh;
    }

    public void setHo(Benof ho) {
        this.ho = ho;
    }

    public void blos() {
        Benof psor = new Benof(504);
        Benof ocom = new Benof(645);
        ocom.coolk(this);
        ocom.setWo(psor);
        Benof.pijur(this, psor);
        psor.iaaPhash();
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: