logo CodeStepByStep logo

Halloween

Language/Type: Java parameters return

For the program below, trace through its execution by hand to show what output is produced when it runs.

/*
 * File: Halloween.java
 * -------------------
 * This program is just testing your understanding of parameter passing.
 */
public class Halloween {
    public static void main(String[] args) {
        int halloweenTown = 10;
        Skeleton bones = new Skeleton("bones");
        Pumpkin king = new Pumpkin(halloweenTown, bones);
        Skeleton skellington = bones;
        skellington.setName("skellington");
        halloweenTown = 5;
        System.out.println(king.toString());
    }
}

public class Pumpkin {
    private int x;
    private Skeleton y;

    public Pumpkin(int z, Skeleton w) {
        x = z;
        y = w;
    }

    public String toString() {
        return y.getName() + " " + x;
    }
}

public class Skeleton {
    private String name;

    public Skeleton(String n) {
        name = n;
    }

    public String getName() {
        return name;
    }

    public void setName(String newName) {
        name = newName;
    }
}
output

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.