- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are multiple inheritances in C#?
C# does not support the usage of multiple inheritances, but it can be implemented using interfaces.
The following is an implementation of Inheritance with Interface. Create two interfaces −
public interface BaseOne { void display(); } public interface BaseTwo { void display(); }
Now set the interfaces like you set the derived classes,
public class ChildOne : BaseOne, BaseTwo { public void display() { Console.WriteLine("Child Class!"); } }
We will call the child class function as shown in the following code to implement multiple inheritance in C# −
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { ChildOne c = new ChildOne(); c.display(); Console.ReadKey(); } } public interface BaseOne { void display(); } public interface BaseTwo { void display(); } public class ChildOne : BaseOne, BaseTwo { public void display() { Console.WriteLine("Child Class!"); } } }
Advertisements