Recall & Review
beginner
What is a constructor in C#?
A constructor is a special method in a class that runs automatically when an object is created. It sets up the object with initial values.Click to reveal answer
beginner
How do you define a constructor in a C# class?
You define a constructor by creating a method with the same name as the class and no return type. For example: <pre>public class Car { public Car() { } }</pre>Click to reveal answer
beginner
What is the purpose of constructor parameters?
Constructor parameters let you pass values when creating an object, so you can set different initial states for each object.Click to reveal answer
intermediate
What happens if you don't define a constructor in a C# class?
C# provides a default parameterless constructor automatically, which initializes fields to default values like 0 or null.
Click to reveal answer
intermediate
Explain constructor chaining in C#.
Constructor chaining means calling one constructor from another in the same class using the <code>: this(...)</code> syntax to reuse initialization code.Click to reveal answer
What is the name of a constructor in C#?
✗ Incorrect
In C#, the constructor must have the same name as the class.
What does a parameterless constructor do?
✗ Incorrect
A parameterless constructor sets fields to default values like 0 or null.
How do you call one constructor from another in the same class?
✗ Incorrect
Constructor chaining uses : this(...) to call another constructor in the same class.
What happens if you define a constructor with parameters but no parameterless constructor?
✗ Incorrect
If you define any constructor, C# does not create a default parameterless constructor automatically.
Which of these is NOT true about constructors?
✗ Incorrect
Constructors cannot be called like normal methods; they run automatically when creating an object.
Describe what a constructor is and why it is useful in C#.
Think about how you prepare a new object when you make it.
You got /4 concepts.
Explain constructor chaining and give an example of when you might use it.
Imagine you want to avoid repeating code in multiple constructors.
You got /4 concepts.