Difficulty: Easy
Correct Answer: A constructor can be used to set default values and limit instantiation.
Explanation:
Introduction / Context:
Constructors initialize objects and can enforce design constraints. Destructors (finalizers) in C# are limited and differ from C++ semantics. This question asks you to identify the accurate statement among common misconceptions.
Given Data / Assumptions:
Concept / Approach:
Constructors can assign default values to fields and may be made private to restrict creation (e.g., singleton, factory-only). C# does not auto-generate copy constructors; developers can write a constructor that copies fields, but it is not provided by the language automatically. Destructors (finalizers) apply only to classes and there can be at most one per class (no parameters, non-overloadable).
Step-by-Step Solution:
Verification / Alternative check:
Inspect C# specification on constructors and finalizers; attempt to add multiple destructors or a struct destructor to observe compiler errors.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming finalizers behave like C++ destructors or that copy constructors are auto-generated in C#.
Final Answer:
A constructor can be used to set default values and limit instantiation.
Discussion & Comments