0

Why default constructor is not running in this case and parameterised constructor is running,when instruction super (10) is

given and when instruction super () is given then default constructor is running but parameterised is not running.what is the reason behind it?? https://code.sololearn.com/ck85wql1p5js/?ref=app

3rd Aug 2017, 3:34 PM
Anum Anand
3 ответов
+ 2
The no parameters constructor will only be invoked (called) if you do not explicitly use the super keyword to call a different constructor. So, only the parameter one was called since you wrote super(10);. Remove that line and the no parameter (or default) constructor will be called.
3rd Aug 2017, 3:50 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
I assume it's so the programmer isn't limited to always having to deal with a no-parameter constructor. Perhaps you want the super class variables to be dependent on what is passed through the sub class constructor. So the no parameter constructor does not have to run if you explicitly tell it not to.
3rd Aug 2017, 4:27 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
i know that by removing super keyword,default constructor will run but what is the reason behind it when we use use keyword with a parameter,paramaterised constructor is running,,bt not default.ideally default constructor has to run @Rrestoring faith
3rd Aug 2017, 4:03 PM
Anum Anand