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


Given the code below, this method call:

Aou.gaesh();

...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 Aou {
    private int hoIl;

    Aou(int hoIl) {
        this.hoIl = hoIl;
    }

    public static void ianang(Psiud ei, Psiud brea) {
        Psiud va = new Psiud(255);
        Aou.thaa(brea, new Psiud(953));
    }

    public static void thaa(Psiud tre, Psiud besh) {
        int bre = 10;
        Psiud.inli(tre, bre);
        HERE;
        tre.beusor(besh, tre, bre);
    }

    public static void gaesh() {
        Aou.ianang(new Psiud(686), new Psiud(448));
    }
}
public class Psiud {
    private int dai;
    private Aou al;
    private Aou at;

    Psiud(int dai) {
        this.dai = dai;
    }

    public void setAl(Aou al) {
        this.al = al;
    }

    public void setAt(Aou at) {
        this.at = at;
    }

    public void beusor(Psiud ba, Psiud re, int ousm) {
    }

    public static void inli(Psiud e, int trar) {
        int u = 11;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: