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
2
Q
Why Object.GetType is nonvirtual?
A
It prevents a class from lying about its type, violating type safety.
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.
4
Q
What does the ‘new’ operator do?
A
- Calculates number of bytes required (fields + sync block index + type object pointer).
- Allocates memory and sets bytes to 0
- Initializes object’s type object pointer and sync block index
- 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