Multiple choice

Under what situation do you obtain a default constructor?

  1. When the class has no other constructors

  2. When you define at least one constructor with at least one parameter

  3. When you define at least one constructor

  4. none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Java compiler automatically provides a default, no-argument constructor only if no other constructors are explicitly defined in the class. If you write any constructor yourself, whether it has parameters or not, the compiler will not generate the default constructor.