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.
The moose likes Java in General and the fly likes abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: abstract class
 
Similar Threads
A mock question
ABSTRACT
usage of a class
HttpServlet class
A question about container!