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


Given the code below, this method call:

Pido.iant();

...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 Pido {
    private int isSabon;
    private Pido ost;

    Pido(int isSabon) {
        this.isSabon = isSabon;
    }

    public void setOst(Pido ost) {
        this.ost = ost;
    }

    public void thel(Pusm oan) {
        this.setOst(this);
        HERE;
    }

    public static void iant() {
        new Pido(923).thel(new Pusm(291));
        new Pusm(360).crupsi();
    }
}
public class Pusm {
    private int skias;

    Pusm(int skias) {
        this.skias = skias;
    }

    public void crupsi() {
        Pusm de = new Pusm(522);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: