Abstract class can have constructors, but an abstract class cannot be insantiated.
Then what is the use of a constructor in an abstract class?
Thanks.
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
Originally posted by rengarajan vaikuntam:
Then what is the use of a constructor in an abstract class?
You must have a constructor in an abstract class because an abstract class can be extended. When a subclass is instantiated, the superclass must be initialized prior to the sublcass' initialization. This is because the superclass, which may contain data members, might also include the initialization procedures for those members. If that code was not executed, it's possible that not all subclass members (some of which may be inherited from the abstract class) would be initialized properly.