• 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

constructor in abstract classes?

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I was wondering why there are constructor in abstract classes when you cannot make an object of it. Any particular use.
regards,
arun
 
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract classes are meant to be subclassed, when an instance of a subclass is being created, the constructor of its superclass would be called firstly, so, you can think the superclass's constructor is a partial constructor of its subclasses.
Constructors are to initialise instances, if you find you are repeately doing same things of initialization in the subclasses of a superclass, you might move them to the constructor of the superclass. In another word, put the "common factor" of the constructors of the subclasses' to the constructor of the superclass. Therefore you not only save lines of code, your code is also semantically clearer, and of course, easier for you to maintain your code.
regards,
Ellen
[ July 24, 2003: Message edited by: Ellen Zhao ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic