+ 2

Methods in super class are inherited to child class. But for parameter constructors why we are using super keyword in sub class.

Why they are not inherited automatically as like normal methods

13th Apr 2019, 2:40 PM
Pravallika
2 odpowiedzi
+ 1
Parent class contain default constructor and parameter constructor .child class contain default and parameter constructor .if I create object to child class constructor with parameters then it calls default constructor in parent and parameter constructor in child class .why it doesn't call parameter constructor in parent class .using super (parameter) in child class it calls parameter constructor of parent class
13th Apr 2019, 3:13 PM
Pravallika
+ 1
From a practical side: Often the child classes, besides specialized behaviour, also have additional members. By using the 'super' you don't have to rewrite code that's gonna be the same for the children; you let the base's constructor handle what it can handle and only manually take care of the arguments that are different.
13th Apr 2019, 4:36 PM
HonFu
HonFu - avatar