aspose file tools*
The moose likes Java in General and the fly likes relation between child and parent class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "relation between child and parent class" Watch "relation between child and parent class" New topic
Author

relation between child and parent class

sonu raj
Ranch Hand

Joined: Jul 31, 2012
Posts: 43

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: 4181
    
  21

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: 43

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: relation between child and parent class