The moose likes Beginning Java and the fly likes constructor in abstract classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor in abstract classes?" Watch "constructor in abstract classes?" New topic

constructor in abstract classes?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
I was wondering why there are constructor in abstract classes when you cannot make an object of it. Any particular use.
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
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.
[ July 24, 2003: Message edited by: Ellen Zhao ]
I agree. Here's the link: http://aspose.com/file-tools
subject: constructor in abstract classes?
Similar Threads
WA #1.....word association
Abstract class constructor
Can i have a private constructor in an abstract class
Why constructor in Abstract class