• 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

abstract Classes

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q. Why does Java allow abstract Classes to have Constructors when we never expect to create Objects of this class.
Besides even when we use these Classes as a Reference to Child Classes.What good are the constructors.
Can anyone please clarify the use of this?

Thanks
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every class extends (directly or indirectly) Object and therefore has a constructor.
By creating an instance of a derived class you're implicitly calling the constructor of the abstract class which can then initialise the data in the abstract class which is not directly accessible by the derived class.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that every constructor that does not contain a call to this:


automatically has a call to super inserted:



so, if SomeClass extends an abstract class, and the constructor implicitly calls super(), it would seem that the abstract class would have to have a constructor, even if its not directly usable by the developer. Just my thtoughts, if anyone knows more about this, I'd be interested in learning.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic