+ 2

While invoking sub class usin constructor how the super class gets executing first?

20th Aug 2018, 4:06 PM
A.G.RAGHUL
A.G.RAGHUL - avatar
6 Réponses
+ 2
A.G.RAGHUL , I am not aware about Java much but this is common concept of Oops. it's build like that way.. reason is that super class members are inherited in sub class.. constructor of sub class initialise sub class members... so, to initiate super class member available in sub class, constructor of super class gets executed
20th Aug 2018, 5:03 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Specify the language please.
20th Aug 2018, 4:14 PM
TurtleShell
TurtleShell - avatar
+ 1
java
20th Aug 2018, 4:16 PM
A.G.RAGHUL
A.G.RAGHUL - avatar
+ 1
but while calling sub class function through object the base class function is not called
20th Aug 2018, 5:05 PM
A.G.RAGHUL
A.G.RAGHUL - avatar
+ 1
it's not called but they are available to you if you wish... constructor allocates memory and initialise member variables (not functions) by getting called before sub class constructor
20th Aug 2018, 5:09 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
👍
20th Aug 2018, 5:10 PM
A.G.RAGHUL
A.G.RAGHUL - avatar