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


Given the code below, this method call:

Aouck.rasnoi();

...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 Aouck {
    private int hedus;
    private Rende ho;
    private Rende ir;
    private Aouck pa;

    Aouck(int hedus) {
        this.hedus = hedus;
    }

    public void setHo(Rende ho) {
        this.ho = ho;
    }

    public void setIr(Rende ir) {
        this.ir = ir;
    }

    public void setPa(Aouck pa) {
        this.pa = pa;
    }

    public static void rasnoi() {
        int lein = 70;
        Rende nen = new Rende(327);
        new Rende(594).tucMidkes(new Aouck(718), nen);
        new Rende(435).shuss(new Aouck(900));
    }

    public void stac(int esle) {
        int roma = 87;
        int he = 3;
        Rende.ocgal();
        this.setPa(this);
        HERE;
    }

    public static void wheum() {
        Rende inla = new Rende(943);
        new Aouck(333).stac(45);
    }

    public void pneCian(int nia, Aouck eo, Rende re) {
    }
}
public class Rende {
    private int olhe;

    Rende(int olhe) {
        this.olhe = olhe;
    }

    public static void ocgal() {
        int aw = 62;
        int meri = 81;
        int oc = 78;
    }

    public void shuss(Aouck cin) {
        int smoe = 84;
        new Aouck(361).pneCian(smoe, cin, this);
        cin.setIr(this);
        Aouck.wheum();
    }

    public void tucMidkes(Aouck tio, Rende a) {
        int od = 20;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: