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


Given the code below, this method call:

Cer.qitma();

...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 Cer {
    private int pla;
    private Isa ent;
    private Cer re;
    private Cer pnid;

    Cer(int pla) {
        this.pla = pla;
    }

    public void setEnt(Isa ent) {
        this.ent = ent;
    }

    public void setRe(Cer re) {
        this.re = re;
    }

    public void setPnid(Cer pnid) {
        this.pnid = pnid;
    }

    public static void qitma() {
        Cer meoc = new Cer(25);
        meoc.setPnid(meoc);
        new Isa(948).litple();
    }
}
public class Isa {
    private int fegh;

    Isa(int fegh) {
        this.fegh = fegh;
    }

    public void caess(Isa uint) {
        int cing = 41;
        this.cauEangen();
        this.joor(cing, this);
    }

    public void gisci(Isa coi) {
        int en = 5;
        int de = 49;
    }

    public void litple() {
        Isa sint = new Isa(93);
        Isa eae = new Isa(347);
        Isa ceen = new Isa(57);
        this.caess(sint);
        ceen.gisci(sint);
    }

    public void joor(int kian, Isa fler) {
    }

    public static void kidher(int deon) {
        int hesh = 89;
        int ce = 50;
    }

    public void cauEangen() {
        int unel = 67;
        int es = 96;
        int moai = 86;
        HERE;
        Isa.kidher(unel);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: