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


Given the code below, this method call:

Cussi.motne();

...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 Cussi {
    private int chu;
    private Aior vib;

    Cussi(int chu) {
        this.chu = chu;
    }

    public void setVib(Aior vib) {
        this.vib = vib;
    }

    public static void motne() {
        Aior or = new Aior(297);
        new Aior(108).conta(new Aior(470));
    }

    public static void lerhal(Aior la, Aior sa) {
        la.slil();
        HERE;
    }
}
public class Aior {
    private int tudod;
    private Cussi ea;

    Aior(int tudod) {
        this.tudod = tudod;
    }

    public void setEa(Cussi ea) {
        this.ea = ea;
    }

    public static void pisbi() {
        int aang = 87;
    }

    public void conta(Aior tuss) {
        Aior ad = new Aior(21);
        Aior.pisbi();
        Cussi.lerhal(tuss, ad);
    }

    public void slil() {
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: