Default Constructor in Java
Fast recall
Quick revision
Core answer
super(). If the superclass has no accessible no-argument constructor, that generated call causes a compile-time error. A no-arg constructor written by the developer is not called a default constructor.Whether you know the compiler only provides a default constructor when none is declared, and the consequence of declaring a parameterized one.
Believing the default constructor always exists, then hitting a compile error after adding a parameterized constructor.
Tie it to frameworks (Jackson/Hibernate need a no-arg constructor) and the fact the default constructor implicitly calls super().
Interview-ready guide
Interview answer
Think of it as a freebie the compiler hands you, then quietly takes back the moment you start writing constructors yourself. If your class declares no constructor at all, the compiler inserts a no-argument one that just calls super() and leaves the fields at their defaults — so new User() works even though you never wrote it.
The catch is that this is conditional. Write a single constructor of your own, even a parameterized one, and the compiler stops generating the free version. So the day you add User(String name), a plain new User() stops compiling — and the fix is just to declare the empty User() {} yourself.
Where this really bites is frameworks. Jackson and Hibernate build objects through reflection using that no-arg constructor, so a JPA entity or JSON DTO missing it fails at runtime, not at compile time — far harder to catch. That's why any framework-managed class always gets an explicit no-arg constructor from me, whatever other constructors it has.
Default Constructor in Java
Direct Answer
The default constructor is the no-argument constructor Java declares only when a class declares no constructor. It has the same accessibility as the class and invokes super(). If the superclass has no accessible no-argument constructor, that generated call causes a compile-time error. A no-arg constructor written by the developer is not called a default constructor.
Common Mistakes & Pitfalls
- Assuming the default constructor is always there — it exists only when you declare no constructors at all; adding any constructor removes it.
- Adding a parameterized constructor and still calling
new User()— the no-arg default is gone, so this becomes a compile error until you re-addUser() {}yourself. - Forgetting the no-arg constructor on entities and DTOs — Jackson and Hibernate instantiate via reflection, so a missing no-arg constructor fails at runtime, not at compile time.
- Confusing 'default constructor' with 'a constructor that sets defaults' — the term means the compiler-generated no-arg one specifically, not any constructor that happens to assign default values.
Check your understanding
Answer these without looking back at the article.
- Why does Hibernate require a no-argument constructor?
- What does the default constructor do internally?
- Can you explicitly define a no-arg constructor if you also have parameterized constructors?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.