This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
what is the use of constructor in a abstract class
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
All classes must have, at a minimum, a default (parameterless) constructor, even classes which cannot be instantiated. A constructor for an abstract class is no different than one for a concrete class. You do any necessary initialization and configuration in an abstract class' constructor just like you do in any other constructor.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
A constructor of an abstract class might enforce the need for parameter(s) at instantiation time. The following example doesn't demonstrate the reasons for having such an enforcement, as this would require a real world scenario, perhaps you can provide an analogy for yourself. Consider: abstract class A { // Enforce the need for a String argument for instantiation. A(String s){/*blah*/} } class B extends A { B() { // Remove the following line and super() is assumed which won't compile // because there is no super default constructor. super("blah"); } }