File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

eswar kumar
Ranch Hand

Joined: Oct 20, 2002
Posts: 98
what is the use of constructor in a abstract class
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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
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");
}
}


Tony Morris
Java Q&A (FAQ, Trivia)
 
Consider Paul's rocket mass heater.
 
subject: abstract class