Recall & Review
beginner
What is a default constructor in Java?
A default constructor is a constructor that Java provides automatically if no other constructors are defined. It has no parameters and initializes objects with default values.
Click to reveal answer
intermediate
What happens if you define a constructor with parameters but no default constructor in your class?
Java will NOT provide a default constructor automatically. You must define the default constructor yourself if you want one.
Click to reveal answer
beginner
How does Java initialize fields when using the default constructor?
Java sets numeric fields to 0, boolean fields to false, and object references to null by default.
Click to reveal answer
beginner
Code snippet: <br>public class Car {<br> String model;<br>}<br>What constructor does this class have by default?This class has a default constructor with no parameters that Java provides automatically. It sets model to null by default.Click to reveal answer
intermediate
Why might you want to explicitly write a default constructor?
To add custom initialization code or to ensure the constructor exists when other constructors are defined.
Click to reveal answer
What does Java provide if you do NOT write any constructor in your class?
✗ Incorrect
Java automatically provides a default constructor with no parameters if you don't write any constructor.
If you write a constructor with parameters, does Java still provide a default constructor?
✗ Incorrect
Java does not provide a default constructor if you define any constructor yourself.
What value does a boolean field have when initialized by the default constructor?
✗ Incorrect
Boolean fields are initialized to false by the default constructor.
Which of these is true about a default constructor?
✗ Incorrect
Java provides a default constructor only if no other constructors are defined.
Why might you write your own default constructor?
✗ Incorrect
Writing your own default constructor lets you add custom code when creating objects.
Explain what a default constructor is and when Java provides it.
Think about what happens if you don't write any constructor.
You got /3 concepts.
Describe why you might need to write your own default constructor in a Java class.
Consider what happens if you add a constructor with parameters.
You got /3 concepts.