+ 1

Why can a subclass inherit the fields, methods, properties and indexers from the superclass, but not the constructors?

?!🤔

18th Nov 2017, 6:55 PM
‏‪‏‪Salah Mahmoud‬‏‬‏
‏‪‏‪Salah Mahmoud‬‏‬‏ - avatar
2 Answers
+ 5
normally a subclass adds attributes. Those new attributes are initialized by the constructor.
18th Nov 2017, 7:05 PM
Oma Falk
Oma Falk - avatar
+ 1
Because you're creating a completely different object. The way you construct one will more than likely not be the way you construct the other. How would the superclass's constructor know about the new properties you created in the subclass? It can't, so that's why you use the superclass's constructor to initialize the properties that it has, and then you use the constructor of the subclass to initialize the properties that it has.
18th Nov 2017, 11:29 PM
Zeke Williams
Zeke Williams - avatar