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


Given the code below, this method call:

Pudum.copit();

...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 Pudum {
    private int sanem;
    private Puc trel;
    private Pudum biss;

    Pudum(int sanem) {
        this.sanem = sanem;
    }

    public void setTrel(Puc trel) {
        this.trel = trel;
    }

    public void setBiss(Pudum biss) {
        this.biss = biss;
    }

    public static void iulAdarm(Pudum e, int ne) {
    }

    public void libis() {
        Pudum ki = new Pudum(645);
        int lo = 17;
        Pudum o = new Pudum(918);
        o.setBiss(ki);
        o.ingma(this);
        o.iodMacka(ki, this);
    }

    public void iodMacka(Pudum ar, Pudum oo) {
    }

    public void ingma(Pudum euft) {
        Puc.gnaad(euft);
        Pudum.iulAdarm(this, 9);
    }

    public static void birIpciar(Pudum cimp) {
        int epe = 97;
    }

    public static void copit() {
        Pudum ho = new Pudum(680);
        Pudum.birIpciar(new Pudum(838));
        new Pudum(834).libis();
    }
}
public class Puc {
    private int icAiu;
    private Pudum eac;

    Puc(int icAiu) {
        this.icAiu = icAiu;
    }

    public void setEac(Pudum eac) {
        this.eac = eac;
    }

    public static void gnaad(Pudum er) {
        Puc el = new Puc(902);
        int pi = 14;
        el.setEac(er);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: