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


Given the code below, this method call:

Suc.kaddo();

...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 Suc {
    private int osTarki;
    private Suc pras;
    private Khei mec;

    Suc(int osTarki) {
        this.osTarki = osTarki;
    }

    public void setPras(Suc pras) {
        this.pras = pras;
    }

    public void setMec(Khei mec) {
        this.mec = mec;
    }

    public static void enged(int ofes) {
        int oi = 48;
    }

    public static void prid(int mict, Suc vuil, int uect) {
        Khei hac = new Khei(194);
        vuil.setMec(hac);
        hac.ransse(hac);
        Suc.plong();
    }

    public static void secor(Khei ta) {
        int tro = 61;
    }

    public static void kaddo() {
        Khei gua = new Khei(747);
        int vipe = 41;
        int el = 95;
        Suc.prid(el, new Suc(866), vipe);
        Suc.enged(vipe);
    }

    public static void plong() {
        int ris = 70;
    }
}
public class Khei {
    private int eswe;
    private Suc go;

    Khei(int eswe) {
        this.eswe = eswe;
    }

    public void setGo(Suc go) {
        this.go = go;
    }

    public void ransse(Khei al) {
        Khei cer = new Khei(946);
        this.vussiw(this, new Khei(588));
    }

    public void vussiw(Khei vi, Khei u) {
        Suc.secor(vi);
        HERE;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: