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


Given the code below, this method call:

Scu.rolCeng();

...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 Scu {
    private int orEr;
    private Injuc stua;
    private Scu sqi;
    private Scu da;
    private Scu nac;

    Scu(int orEr) {
        this.orEr = orEr;
    }

    public void setStua(Injuc stua) {
        this.stua = stua;
    }

    public void setSqi(Scu sqi) {
        this.sqi = sqi;
    }

    public void setDa(Scu da) {
        this.da = da;
    }

    public void setNac(Scu nac) {
        this.nac = nac;
    }

    public static void rolCeng() {
        Scu o = new Scu(408);
        o.setNac(o);
        Injuc.serxes();
    }

    public static void molorm(Injuc e) {
        Injuc us = new Injuc(445);
        Scu onpu = new Scu(324);
    }

    public void scoer(Injuc iss, int pism) {
    }

    public void semcil(Injuc ol, Injuc oss) {
        Scu su = new Scu(429);
        Scu.molorm(ol);
        this.setSqi(su);
        new Injuc(152).hasmi();
        ol.wuelo(su, oss);
    }
}
public class Injuc {
    private int sont;

    Injuc(int sont) {
        this.sont = sont;
    }

    public void hasmi() {
        int in = 75;
        HERE;
    }

    public void wuelo(Scu va, Injuc ral) {
    }

    public static void serxes() {
        Injuc en = new Injuc(473);
        int hos = 53;
        int ac = 58;
        new Scu(878).scoer(en, hos);
        new Injuc(944).sepe(hos, en, ac);
        en.wereel(31, ac);
    }

    public void wereel(int mo, int arto) {
        int pel = 8;
        int je = 49;
    }

    public void sepe(int reiw, Injuc a, int anen) {
        new Scu(278).semcil(a, this);
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: