Things to say about class inheritance in C#

Today, I'm going to briefly summarize what is inherited from a base class

Base class A: Animal

Derived Class D: Dog


1/Cannot instantiate a class with only private constructor. So, This classe(would be base class) can be only inherited

2/The derived class would inherits the base class member variables and member methods (with access modifier Public, Protected). Therefore the base class object should be created before the subclass is created. You can give instructions for base initialization in the member initialization list.


3/For public class, Every method, property, field with the access modifiers such as public, protected  (including constructor) is going to be inherited for the derived class . So carefully when playing with constructor inheritance (because if you have only private constructor (not including public constructor) in base class, it is NOT going to be inherited )

4/ With me, Inheritance would be used to extend and customize base class for derived classes. (See Linked list examples. This is IS-A Relationship, Typical TypedNode is a node, using core of  The node class )

5/ Abstract Classes should be considered when using inheritance. Normally, we will play with a collection of objects of same types. Carefully, abstract should not to contain a constructor.
Share on Google Plus

About Chien

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Post a Comment