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


Given the code below, this method call:

Swion.laspre();

...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 Swion {
    private int rheon;
    private Swion ced;
    private Vecre giu;

    Swion(int rheon) {
        this.rheon = rheon;
    }

    public void setCed(Swion ced) {
        this.ced = ced;
    }

    public void setGiu(Vecre giu) {
        this.giu = giu;
    }

    public static void caproa() {
        Swion.thua(new Vecre(52));
        Swion.coong();
    }

    public static void laspre() {
        Swion clu = new Swion(371);
        Swion trae = new Swion(903);
        int seu = 73;
        clu.setCed(trae);
        new Swion(162).kecRass(trae, clu, new Vecre(22));
    }

    public static void coong() {
        Swion uice = new Swion(19);
        int al = 19;
        int go = 39;
        int clae = 64;
        uice.setCed(uice);
        Vecre.nend(clae);
        Vecre.asmhen(clae, al, uice);
    }

    public void kecRass(Swion pec, Swion adno, Vecre kac) {
        Swion luvu = new Swion(967);
        adno.setCed(luvu);
        Swion.caproa();
        Vecre.trep(pec, adno, this);
    }

    public static void thua(Vecre emau) {
    }

    public static void pseca(int ik) {
        int ka = 29;
        int paci = 31;
        int ul = 40;
    }
}
public class Vecre {
    private int meOu;
    private Vecre ang;
    private Swion espa;

    Vecre(int meOu) {
        this.meOu = meOu;
    }

    public void setAng(Vecre ang) {
        this.ang = ang;
    }

    public void setEspa(Swion espa) {
        this.espa = espa;
    }

    public static void nend(int lopi) {
        int calt = 8;
        int swo = 43;
        int hoor = 11;
        Swion.pseca(calt);
        HERE;
    }

    public static void trep(Swion fic, Swion ste, Swion gak) {
    }

    public static void asmhen(int flid, int cu, Swion aiss) {
        int he = 59;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: