What is a default constructor in Java?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Java development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
A default constructor is a no-argument constructor that Java automatically generates if you do not define any constructor in your class. It initializes instance fields to their default values: 0 for numeric types, false for boolean, null for object references. Example: new MyClass() works even if you never wrote a constructor — Java provided the default one. However, if you define any constructor with arguments, Java no longer generates the default constructor. If you still need a no-argument constructor along with parameterized ones, you must explicitly define it: public MyClass() { }.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Java answers easy to follow.