Monday, 30 July 2012

Inheritance with an example in C#.NET


Inheritance with an example in C#.NET

Creating a new class from existing class is called as inheritance. 


When a new class needs same members as an existing class then instead of creating those members again in new class, the new class can be created from existing class, which is called as inheritance.


Main advantage of inheritance is reusability of the code.


During inheritance, the class that is inherited is called as base class and the class that does the inheritance is called as derived class and every non private member in base class will become the member of derived class.

Inheritance can be classified to 5 types.


  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multi Level Inheritance
  4. Hybrid Inheritance
  5. Multiple Inheritance
1. Single Inheritance

when a single derived class is created from a single base class then the inheritance is called as single inheritance.


2. Hierarchical Inheritance
when more than one derived class are created from a single base class, then that inheritance is called as hierarchical inheritance.

3.Multi Level Inheritance
when a derived class is created from another derived class, then that inheritance is called as multi level inheritance.


4. Hybrid Inheritance
Any combination of single, hierarchical and multi level inheritances is called as hybrid inheritance.

5. Multiple Inheritance
when a derived class is created from more than one base class then that inheritance is called as multiple inheritance. But multiple inheritance is not supported by .net using classes and can be done using interfaces.


Note:Handling the complexity that causes due to multiple inheritance is very complex. Hence it was not supported in dotnet with class and it can be done with interfaces.



8 comments:

  1. it is very good explanation of Inheritance

    ReplyDelete
  2. Inheritance is a concept of deriving the features from one class to another class. Inheritance leads to Read more
    Check this siteTeKslate for indepth C# training.
    Go here if you’re looking for information on C# Training.

    ReplyDelete
  3. good example and content of this blogs so easy and understandable ......

    ReplyDelete
  4. Sir theory is best but plz give its example of inherritance through programming bhi do...:)

    ReplyDelete
  5. it's a nice article and very interesting topic because of this inheritance concept only we can achive dynamic binding, loose coupling.
    To get more knowledge on inheritance concept
    logon this website http://techenoid.com/

    ReplyDelete
  6. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    spoken english classes in chennai | Communication training

    ReplyDelete