The default constructor is used when no arguments are specified when a single class is instantiated but for the subclass and superclass , we need to necessarily create the default constructors ! Why?
-
[Here you will get the exact meaning](https://www.quora.com/Why-do-we-need-to-declare-default-constructors-in-Java-classes) – Laxminarayan Aug 18 '18 at 09:20
-
9It is not necessary, why do you think it is necessary? You may want to illustrate your question with code, so that we can better understand what is going and then explain it to you. – Mark Rotteveel Aug 18 '18 at 09:22
-
we actually dont need to. one of superclasses constructors has to be necessarily invoked when instantiating a subclass, so if the superclass has a default constructor, you do not have to specify any in the subclass of this superclass because no-args constructor will be invoked automatically – nyarian Aug 18 '18 at 09:24
-
Can you give an example? – Henry Aug 18 '18 at 09:24
-
1You may want to look at https://stackoverflow.com/questions/10508107/why-call-super-in-a-constructor – Mark Rotteveel Aug 18 '18 at 09:28
-
Welcome to Stack Overflow! Please take the [tour] (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Stack Overflow is a *very* active place. When you post a question (or answer), please *stick around* for a few minutes so you can clarify what you're asking (or answering) when people ask you to. – T.J. Crowder Aug 18 '18 at 09:32
-
*"marked as duplicate by T.J. Crowder, GhostCat"* ***sigh*** [I wish SO would fix this blatant bug](https://meta.stackexchange.com/questions/269073/dont-say-i-marked-something-as-a-duplicate-when-i-didnt). No, I did not vote to close this as a duplicate. – T.J. Crowder Aug 18 '18 at 09:39
2 Answers
Note: "Default constructor" != "Zero parameters constructor". The default, if supplied, is a zero-parameters constructor, but if you explicitly write a zero-parameters constructor, that's not a default.
Why is it necessary to create a default constructor in java?
It isn't — that's why it's called a default constructor. The compiler provides it if you don't write any constructors for your class. The default constructor accepts no parameters and, if your class is a subclass, calls the zero-parameters constructor on the superclass.
This works just fine (live copy):
class Base {
}
class Derived extends Base {
}
// ...
Derived d = new Derived();
You only need to define a zero-parameters constructor if:
- You want it to have different accessibility than the default (by default it has the same accessibility as the class).
- You define any other constructors, but also want to have a zero-parameters constructor. This is because the compiler provides the default only if no constructors are defined (since you may not want a zero-parameters constructor).

- 1,031,962
- 187
- 1,923
- 1,875
The default constructor is the no-argument constructor automatically generated if you don't define another constructor.
However, if you define at least one constructor, the default constructor is not generated. So, don't confuse the default constructor with the constructor no-argument.
When you create class A extends class B, inside the constructor of A (default or defined), if you don't explicitly call super(...), the default super() (no-arguments) is invoked implicitly.
If you have only defined constructors with arguments in the class B, this super() - calls the constructor (no-arguments) of B - is not defined --> error.
That's the reason why you think you must have a default constructor with no arguments for subclasses.

- 649
- 6
- 13