Chapter 5 – Building Your Own Types with ObjectOriented Programming Flashcards

1
Q

What are the six combinations of access modifier keywords and what do they do?

A

The six combinations of access modifier keywords and their effects are described in
the following list:
* private: This modifier makes a member only visible inside the class.
* internal: This modifier makes a member only visible inside the same assembly.
* protected: This modifier makes a member only visible inside the class or derived
classes.
* internal protected: This modifier makes a member only visible inside the class,
derived classes, or within the same assembly.
* private protected: This modifier makes a member only visible inside the class or
derived classes that are within the same assembly.
* public: This modifier makes a member visible everywhere.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between the static, const, and readonly keywords when applied to
a type member?

A

The difference between the static, const, and readonly keywords when applied to
a type member is described in the following list:
* static: This keyword makes the member shared by all instances and it must be accessed
through the type, not an instance of the type.
* const: This keyword makes the field a fixed literal value that must never change because during the compilation, assemblies that use the field copy the literal value at
the time of compilation.
* readonly: This keyword restricts the field so that it can only be assigned to using a
constructor or field initializer at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a constructor do?

A

A constructor allocates memory and initializes field values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do you need to apply the [Flags] attribute to an enum type when you want to store combined values?

A

If you don’t apply the [Flags] attribute to an enum type when you want to store combined values, then a stored enum value that is a combination will be returned by a call to
ToString as the stored integer value, instead of one or more of the comma-separated list of
text values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is the partial keyword useful?

A

You can use the partial keyword to split the definition of a type over multiple files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a tuple?

A

A tuple is a data structure consisting of multiple parts. They are used when you want
to store multiple values as a unit without defining a type for them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the record keyword do?

A

The record keyword defines a data structure that is immutable by default to enable a
more functional programming style. Like a class, a record can have properties and methods,
but the values of properties can only be set during initialization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does overloading mean?

A

Overloading is when you define more than one method with the same method name
and different input parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between a field and a property?

A

A field is a data storage location that can be referenced. A property is one or a pair of
methods that get and/or set a value. The value of a property is often stored in a private field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you make a method parameter optional?

A

You make a method parameter optional by assigning a default value to it in the method
signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly