• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

relation between child and parent class

 
Ranch Hand
Posts: 43
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sonu raj
Ranch Hand
Posts: 43
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic