2025-03-06

Warm-up Exercises

Questions

In C# each class you create becomes a new type and you can create objects of this type.

☒ Yes

☐ No

What is “an instance of the class”?

Solution

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

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

Solution

Rectangle myRectangle = new Rectangle();

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

Solution

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

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