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


Given the code below, this method call:

Ierd.triong();

...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 Ierd {
    private int thi;
    private Ard ru;

    Ierd(int thi) {
        this.thi = thi;
    }

    public void setRu(Ard ru) {
        this.ru = ru;
    }

    public static void triong() {
        Ierd niap = new Ierd(312);
        Ierd elpa = new Ierd(889);
        Ierd.mencac();
        new Ierd(578).feng(elpa, niap);
    }

    public static void mencac() {
        Ierd in = new Ierd(743);
    }

    public void feng(Ierd is, Ierd dass) {
        HERE;
    }
}
public class Ard {
    private int wedbi;

    Ard(int wedbi) {
        this.wedbi = wedbi;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: