cs2 - types Flashcards

1
Q

What is the set of methods in System.Object. What are access modifiers for them?

A
Equals - public virtual
GetHashCode - public virtual
ToString - public virtual
GetType - public NONvirtual
MemberwiseClone - protected NONvirtual
Finalize - protected virtual
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why Object.GetType is nonvirtual?

A

It prevents a class from lying about its type, violating type safety.

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

What does Object.MemberwiseClone do?

A

Creates a new instance of the type and sets the new object’s instance fields to be identical to the ‘this’ object’s fields. A reference to new instance is returned.

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

What does the ‘new’ operator do?

A
  1. Calculates number of bytes required (fields + sync block index + type object pointer).
  2. Allocates memory and sets bytes to 0
  3. Initializes object’s type object pointer and sync block index
  4. Type’s instance constructor is called

more specific:
Member variables are initialized to default values for all classes in the hierarchy
Then starting with the most derived class:

Variable initializers are executed for the most-derived type
Constructor chaining works out which base class constructor is going to be called
The base class is initialized (recurse all of this :)
The constructor bodies in the chain in this class are executed (note that there can be more than one if they're chained with Foo() : this(...) etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly