Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class

 
eswar kumar
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the use of constructor in a abstract class
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic