0

Why do we need to insert same parameters of superclass constructor() in the super() method within subclass constructor()

14th Aug 2022, 12:26 PM
Ahamed Shifak
Ahamed Shifak - avatar
3 Antworten
+ 1
Ahamed Shifak because the super keyword is used to call the constructor of its parent class to access the parent's properties and methods. So if parent class constructor have parameters then you have to pass with super.
14th Aug 2022, 1:15 PM
A͢J
A͢J - avatar
+ 1
Ahamed Shifak It is not necessary that subclass constructor and parent class constructor should have same parameters. Also it is not necessary super should have an argument. If you make parent class constructor with parameters then you have pass argument with super. You can write super without argument also, constructor will be call but you may get undefined because you are not providing argument https://code.sololearn.com/W6sNy1wg1zmn/?ref=app
14th Aug 2022, 3:41 PM
A͢J
A͢J - avatar
0
But why do we code it in both the constructor parantheses of subclass and super method parantheses
14th Aug 2022, 1:32 PM
Ahamed Shifak
Ahamed Shifak - avatar