• 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

Inheritance and Constructors...

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

There is a doubt about inheritance and constructors
In the simplest words , any thing which is not private in a super class is inherited to the sub class.
What happens to constructors ?
As I read they are not inherited .

How this is working... any inside look on the matter, please

Thanks
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No constructors are not inherited. Constructors are used to initialize the instance variables in a class definition when an instance is created. The nice thing about the inheritance mechanism is that when a subclass is created, a constructor from the superclass is always called. So we do not have to redo all of the work done in the superclass to initialize its variables, we can simply invoke the appropriate superclass constructor and have it initliaze the variables that the superclass gives to the subclass, and the subclass can take care of initializing the variables it adds to what the superclass gives it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic