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


Given the code below, this method call:

Pasel.qiaNiu();

...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 Pasel {
    private int prosh;
    private Biue cic;

    Pasel(int prosh) {
        this.prosh = prosh;
    }

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

    public static void qiaNiu() {
        Biue de = new Biue(46);
        int whi = 91;
        Biue.ches(de, new Biue(559));
    }

    public void zucant() {
    }
}
public class Biue {
    private int edca;

    Biue(int edca) {
        this.edca = edca;
    }

    public static void ches(Biue arpe, Biue nac) {
        new Pasel(450).zucant();
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: