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


Given the code below, this method call:

Curul.pames();

...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 Curul {
    private int bucac;
    private Curul bre;
    private Curul sce;

    Curul(int bucac) {
        this.bucac = bucac;
    }

    public void setBre(Curul bre) {
        this.bre = bre;
    }

    public void setSce(Curul sce) {
        this.sce = sce;
    }

    public void plePasm(Balvi go, int e) {
    }

    public static void plit(int he) {
        Balvi deah = new Balvi(596);
    }

    public static void pames() {
        int fi = 58;
        Balvi la = new Balvi(130);
        int riir = 19;
        new Balvi(254).ictRac();
        new Curul(304).plePasm(la, fi);
    }
}
public class Balvi {
    private int orPril;

    Balvi(int orPril) {
        this.orPril = orPril;
    }

    public void ictRac() {
        int oeae = 64;
        Curul ded = new Curul(108);
        ded.setBre(ded);
        Balvi.noass(ded);
    }

    public static void noass(Curul onhi) {
        onhi.setSce(onhi);
        HERE;
        Curul.plit(60);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: