• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance issue

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a question that whenever I create the object of the derived class the constructor of superclass gets called.
I mean to say a constructor is called only when the object is created does that mean that whenever I create derievd class Object superclass Object also gets created.

Further I want to ask instance method is called only when object exists but I can call the superclass instance method
from the subclass method which I have overridden in subclass. without creating the superclass object.
How?

Thanks.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rakesh kankavlikar wrote:
I have a question that whenever I create the object of the derived class the constructor of superclass gets called.
I mean to say a constructor is called only when the object is created does that mean that whenever I create derievd class Object superclass Object also gets created.


Your Sub class Constructor calls "super()"[it calls your Super Classe's default Constructor] in his first line implicitly. please Avoid the term of "derived class " . it is not C++

rakesh kankavlikar wrote:
Further I want to ask instance method is called only when object exists but I can call the superclass instance method
from the subclass method which I have overridden in subclass. without creating the superclass object.
How?



that is what IS-A relationship is
 
reply
    Bookmark Topic Watch Topic
  • New Topic