Showing posts with label Inheritance. Show all posts
Showing posts with label Inheritance. Show all posts

C# - Inheritance


nheritance is one of the main features of an object-oriented language. C# and the .NET class library are heavily based on inheritance. The telltale sign of this is that all .NET common library classes are derived from the object class, discussed at the beginning of this article. As pointed out, C# doesn’t support multiple Inheritance. C# only supports single inheritance; therefore, all objects are implicitly derived from the object class.
Implementing inheritance in C# is similar to implementing it in C++. You use a colon (:) in the definition of a class to derive it from another class.
 

Inheritance ....cont

What is inherited from the base class?
In principle every member of a base class is inherited by a derived class except:
         Constructor and destructor
         operator=()member
         friends
Although the constructor and destructor of the base class are not inherited, the default constructor and the destructor of the base class are alwyas called when a new object of a derrived class is created and destrroyed.   LEARN MORE>>

Inheritance between Classes

An important feature of classes is inheritance. This allows us to create an object derived from another one, so that it may include some of the other's members plus its own. For example, we are going to suppose that we want to declare a series of classes that describe polygons like our CRectangle, or CTriangle. They have certain common features, such as both can be described by means of only two sides: height and base.
This could be represented in the world of classes with a class CPolygon from which we would derive the two referred ones: CRectanble and CTriangle ....LEARN MORE>>