Warm-up Exercises

Questions

  1. In C# each class you create becomes a new type and you can create objects of this type.
  • Yes
  • No
  1. What is “an instance of the class”?

Solution

An instance of a class is an object created using the class as a blueprint.

  1. Write a statement that creates a new object from the Rectangle class.

Solution

Rectangle myRectangle = new Rectangle();

  1. Do different objects from the same class share an instance variable?

Solution

No, each object contain instance variables separate from those of other objects.

  1. Suppose we have a Circle class containing
public void SetRadius(double RadiusArgument)
{
    radius = RadiusArgument;
}

Write a statement that creates a Circle object, and one statement that sets its radius to 3.5.

Solution

Circle circle1 = new Circle(); circle1.SetRadius(3.5);

Problems