Q

What is the use of these constructors?

I have wondered: Abstract classes may contain constructors. But, when we cannot instantiate the abstract classes, what is the use of these constructors? - N.K.

Those constructors usually are protected and never public. Actually, that's something that the FxCop tool (www.gotdotnet.com/team/fxcop/) will enforce in your assemblies - if you are not using that tool, you should consider it right away. It enforces best practices across your code.

So, the constructor serves the purpose of initializing whatever is needed on the base abstract class, whenever a descendant class is created. Note that if the abstract class offers only a single version of the constructor – say, receiving a parameter, or not receiving a parameter – it HAS to be called by the descendant class. In the case of a 'parameterless' constructor, this happens automatically whenever the derived class is constructed.

This was last published in April 2005

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close