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


Given the code below, this method call:

Jouru.hisfan();

...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 Jouru {
    private int enErra;

    Jouru(int enErra) {
        this.enErra = enErra;
    }

    public void vacol(Ihism inhi) {
        Jouru a = new Jouru(439);
    }

    public static void cinCiaoc() {
        Jouru.perta();
    }

    public static void triom(Jouru o, Jouru tu) {
        int nier = 18;
    }

    public static void hisfan() {
        Ihism te = new Ihism(25);
        Ihism ur = new Ihism(864);
        new Jouru(911).vacol(te);
        ur.setEsmi(te);
        Jouru.cinCiaoc();
    }

    public static void perta() {
        Jouru ost = new Jouru(45);
        Jouru whol = new Jouru(442);
        Jouru.triom(whol, ost);
        HERE;
    }
}
public class Ihism {
    private int anrun;
    private Jouru pe;
    private Ihism esmi;

    Ihism(int anrun) {
        this.anrun = anrun;
    }

    public void setPe(Jouru pe) {
        this.pe = pe;
    }

    public void setEsmi(Ihism esmi) {
        this.esmi = esmi;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: