logo CodeStepByStep logo

Halloween

Language/Type: C# parameters return

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

/*
 * File: Halloween.cs
 * ------------------
 * This program is just testing your understanding of parameter passing.
 */
public class Halloween
{
    public static void Main()
    {
        int halloweenTown = 10;
        Skeleton bones = new Skeleton("bones");
        Pumpkin king = new Pumpkin(halloweenTown, bones);
        Skeleton skellington = bones;
        skellington.Name = "skellington";
        halloweenTown = 5;
        Console.WriteLine("king is {0}", king);
    }
}

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

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

    public override string ToString()
    {
        return y.Name + " " + x;
    }
}

public class Skeleton
{
    private string name;

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

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
}
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.