| Claim | Verdict |
|---|
| Every class gets a default constructor | False. Only classes declaring none. |
| It is always public | False. It matches the class modifier. |
| It assigns default values to fields | True in effect, but the JVM does that, not it. |
| It calls super automatically | True. That is its only statement. |
| Subclasses inherit it | False. Constructors are never inherited. |
| Adding a no-arg constructor removes it | True. The signature survives, the body changes. |
| You can see it in your source file | False. It exists only in the bytecode. |
| Records and enums get one too | False. Both have their own construction rules. |
Frequently Asked Questions
When does the compiler generate a default constructor?
Only when a class body declares no constructor of any kind. Declaring a parameterized constructor, a no-argument constructor, or even a private one all suppress generation, since the condition is that no constructor appears in the source rather than that no usable one exists.
What does the generated constructor contain?
A single statement, an implicit call to the parent no-argument constructor. It assigns no fields and performs no validation, so every field keeps the JVM default for its type, which is zero for primitives, false for boolean, and null for reference types.
What is the access modifier of the generated constructor?
The same as the class declaration. A public class receives a public default constructor, while a package-private class receives a package-private one, which means it cannot be constructed from another package until you write an explicit public constructor.
Why does adding a constructor break code elsewhere?
Because it suppresses generation, so a signature that other files relied on disappears without any edit to those files. The compile error appears at a call site that was never modified, and searching the source for the missing constructor finds nothing because it was never written down.
Does adding an explicit no-argument constructor change anything?
The signature stays available, so no call site breaks, but the body and access level become yours to control. That is precisely how you replace a default constructor that is too permissive, or one that leaves required fields at null.
Why can a class with a final field fail to compile?
A final field must be assigned exactly once, and the compiler checks that for every constructor, including the generated one. Since the generated body assigns nothing, the requirement cannot be met. Declaring any constructor, which can perform the assignment, resolves it.
Do subclasses inherit the default constructor?
No, constructors are never inherited. A subclass must invoke a parent constructor through super, or the compiler inserts a call to the parent no-argument constructor. If the parent declares only parameterized constructors, a subclass with no explicit constructor fails to compile.
How can I see whether a default constructor was generated?
Use a decompiler such as javap on the compiled class, which will show a public constructor with an empty body apart from the super call. It never appears in your source, and IDE features such as generated constructor insertion make the behaviour explicit rather than implicit.