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


Given the code below, this method call:

Bip.scre();

...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 Bip {
    private int kiAtu;

    Bip(int kiAtu) {
        this.kiAtu = kiAtu;
    }

    public static void hinte(Bip alno, Bip ot, Bip sesm) {
        sesm.memod();
        HERE;
    }

    public static void scre() {
        Bip sphi = new Bip(791);
        Bip.hinte(new Bip(79), sphi, new Bip(695));
    }

    public void memod() {
        int etio = 5;
    }
}
public class Ene {
    private int enpir;
    private Bip cic;

    Ene(int enpir) {
        this.enpir = enpir;
    }

    public void setCic(Bip cic) {
        this.cic = cic;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: