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


Given the code below, this method call:

Repsa.osca();

...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 Repsa {
    private int rasme;
    private Miard ci;

    Repsa(int rasme) {
        this.rasme = rasme;
    }

    public void setCi(Miard ci) {
        this.ci = ci;
    }

    public void esdard(int pano, int brec, Miard ska) {
    }

    public static void priaiu() {
        int cror = 94;
        int ves = 12;
        int co = 94;
        int gime = 27;
    }

    public void sust() {
        Repsa cou = new Repsa(279);
        int a = 20;
        cou.blucad();
        Repsa.priaiu();
    }

    public void blucad() {
        Miard pa = new Miard(767);
        int de = 21;
        int whu = 78;
        this.esdard(de, whu, pa);
        pa.setOs(this);
        Repsa.liaInrerd(whu, this);
    }

    public static void osca() {
        Miard an = new Miard(230);
        int ad = 94;
        int plol = 25;
        Repsa zem = new Repsa(903);
        zem.setCi(an);
        new Repsa(637).sust();
        Miard.priCec(plol, ad);
    }

    public static void liaInrerd(int he, Repsa o) {
        int li = 77;
        HERE;
    }
}
public class Miard {
    private int secti;
    private Repsa os;
    private Miard phau;

    Miard(int secti) {
        this.secti = secti;
    }

    public void setOs(Repsa os) {
        this.os = os;
    }

    public void setPhau(Miard phau) {
        this.phau = phau;
    }

    public static void priCec(int flel, int du) {
        int tiri = 72;
    }
}

Solution

Hints for practicing this puzzle:


Related puzzles: