| Author |
relation between child and parent class
|
sonu raj
Ranch Hand
Joined: Jul 31, 2012
Posts: 33
|
|
If child class is instantiated then the constructor of parents class is called first(super() is added by jvm in constructor of child class), so my question is while creating object of child class whether the object of parent class is created or not
for example
Output:
Parent Constructor
Child Constructor
Because super() is added by jvm as the first statement in constructor of Child class so I wanted to know whether the object of Parent class is created or not. how?
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3090
|
|
|
There is only one object being created, the instance of Child. But the Child IS-A Parent since it extends Parent, so the single Object that is being created must be a fully functional (and initialized) Parent as well as a fully functional (and initialized) Child. So the first thing that happens is the single Object is created as a Parent first, then 'extended' to include all the initializations for the Child.
|
Steve
|
 |
sonu raj
Ranch Hand
Joined: Jul 31, 2012
Posts: 33
|
|
Steve Luke wrote:There is only one object being created, the instance of Child. But the Child IS-A Parent since it extends Parent, so the single Object that is being created must be a fully functional (and initialized) Parent as well as a fully functional (and initialized) Child. So the first thing that happens is the single Object is created as a Parent first, then 'extended' to include all the initializations for the Child.
Thank You very much Steve
|
 |
 |
|
|
subject: relation between child and parent class
|
|
|