Multiple Inheritance in C#

Ganeshji
Posted by in C# category on for Beginner level | Points: 250 | Views : 76020 red flag
Rating: 4.67 out of 5  
 3 vote(s)

This article shows how multiple inheritance can be effected by the use of interface.


 Download source code for Multiple Inheritance in C#

Introduction


In C# Multiple Inheritance can be effected using Interface. We can implement multiple interfaces. But we cannot inherit multiple Base Classes.


Single Class inheritance







Output





A Class cannot have multiple Base Classes





Here intellisense is also not providing the method name of the class B. Thus restricting multiple inheritance using more than one class.

Error Message



Multiple Interfaces can be implemented


Here multiple interfaces can be used using comma(,). Thus allowing multiple inheritance, by implementing more than interface.




Output





Hope this article will be useful.

Thanks!
Page copy protected against web site content infringement by Copyscape

About the Author

Ganeshji
Full Name: Zinnia Sarkar
Member Level:
Member Status: Member
Member Since: 7/24/2010 12:50:40 PM
Country: India
Regards, Ganeshji


Login to vote for this post.

Comments or Responses

Posted by: Karthikanbarasan on: 2/17/2011 | Points: 25
Nice article!!!! please upload the code as well!!!!
Posted by: Ganeshji on: 2/17/2011 | Points: 25
Yes. Thnx again.
Posted by: Madhu.b.rokkam on: 2/17/2011 | Points: 25
I liked it..cool
Posted by: Bugwee on: 2/18/2011 | Points: 25
useful specially for beginners..
Posted by: Ganeshji on: 2/18/2011 | Points: 25
Thnx Kartthikanbarasan, Madhu.b.rokkam and Bugwee. Plz keep on suggesting.
Posted by: Tripati_tutu on: 2/19/2011 | Points: 25
Good article......
Posted by: G on: 3/31/2011 | Points: 25
This does not make sense. Implementing multiple interfaces is not the same as inheritance. You still have to define every method or property of the interfaces in your "Z" class.

Multiple inheritance is just NOT possible in C#, as the first error message mentionned.
Posted by: Akiii on: 8/15/2011 | Points: 25
Good for building concepts...

Thanks and Regards
Akiii
Posted by: Ganeshji on: 8/17/2011 | Points: 25
Thnx Akii!
Posted by: Vijayakumarp on: 3/19/2012 | Points: 25
Good article Zinnia Sarkar..
Posted by: Ganeshji on: 3/19/2012 | Points: 25
Thanks VijayaKumarp!!!
Posted by: Rajesh081725 on: 11/29/2012 | Points: 25
Nice Concepts and Examples
Posted by: Manikandan711 on: 3/3/2013 | Points: 25
Good one..
Posted by: Self-Innovator on: 9/6/2013 | Points: 25
Useful...

Login to post response

Comment using Facebook(Author doesn't get notification)