Constructors Flashcards
1
Q
What is a copy constructor?
A
A constructor that accpets an instance of it’s class, then copies the object (argument) by setting the class’s attributes, etc. to that of the argument
2
Q
Does C# provide a copy constructor?
A
No. C# does not provide a copy constructor by default. The developer must create a copy constructor
3
Q
What is a static constructor?
A
- A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed only once
- Called automatically before the first instance is created or any static members are referenced
- A static constructor is called at most once
- Doesn’t take access modifiers or have parameters
- A class or struct can only have one static constructor
- Cannot invoke static constructor explicitly by the programmer. Only the CLR can invoke it.
- A field declared as static readonly can only be assigned as part of its declaration or in a static constructor
4
Q
Can optional arguments be used with overloaded constructors?
A
Yes. They can.