Preview Questions

9.5. Preview Questions#

Complete these questions before class to prepare for the chapter. Use the dropdowns to check your answers.

9.5.1. True or False#

1. A class in C# is a reference type.

Answer

True — Class instances live on the heap and are accessed via references.

2. A constructor has a return type of void.

Answer

False — Constructors have no return type — not even void.

3. Properties in C# provide controlled access to instance variables.

Answer

True — Properties expose get and set accessors to read/write private fields.

4. The ToString() method must always be explicitly overridden in every class.

Answer

FalseToString() is inherited from object; overriding is optional.

5. In C#, a struct is a value type while a class is a reference type.

Answer

True — Structs are copied on assignment; classes share the same instance via reference.

9.5.2. Multiple Choice#

1. What is the primary purpose of a constructor?

a) To destroy an object when done
b) To initialize a new object’s state
c) To define properties
d) To override inherited methods

Answer

b) To initialize a new object’s state — A constructor sets up a newly created object’s initial state.

2. Which keyword refers to the current instance inside a method?

a) self
b) base
c) this
d) me

Answer

c) thisthis refers to the current object instance.

3. A property with only a get accessor is:

a) Read-write
b) Write-only
c) Read-only
d) Static

Answer

c) Read-only — Without a set accessor, the property can only be read.

4. Which method is implicitly called when an object appears in a string context?

a) Print()
b) Display()
c) Format()
d) ToString()

Answer

d) ToString()Console.WriteLine(obj) calls obj.ToString() automatically.

5. Defining operator + in a class allows you to:

a) Add the class to a namespace
b) Use + with instances of that class
c) Create a subclass
d) Override the Add() method

Answer

b) Use + with instances of that class — Operator overloading lets you write natural expressions like a + b.

Footnotes