When do you call super() in Java?
I see it in some constructors of the derived class, but isn’t the constructors for each of the parent class called automatically? Why would you need to use super?
When do you call super() in Java? I see it in some constructors of
Share
If you provide a class like this:
or this:
the compiler will generate code for this:
So, strictly speaking, the call to “super()” is always there.
In practice you should only call “super(…)” where there are parameters you want to pass to the parent constructor.
It isn’t wrong to call “super()” (with no parameters) but people will laugh at you 🙂