Multiple inheritance in C#
Multiple inheritance allows programmers to create classes that combine aspects of multiple classes and their corresponding hierarchies. For ex. the C++ allows you to inherit from more than one class
In C#, the classes are only allowed to inherit from a single parent class, which is called single inheritance. But you can use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.
You can inherit like the following:
In the above code, the class "NewClass" is created from multiple interfaces.
In the above code, the class "NewClass" is created from interface X and class "FirstClass".
The above code is wrong in C# because the new class is created from class "FirstClass" and class "SecondClass". The reason is that C# does not allows multiple inheritance.
An interface looks like a class, it contain only the declaration of the members but has no implementation. It provides a contract specifying how to create an Object, without caring about the specifics of how they do the things. An Interface is a reference type and it included only the signatures of methods, properties, events or indexers. In order to implement an interface member, the corresponding member of the implementing class should be public, non-static, and have the same name and signature as the interface member. Click here to know more about.... C# Interfaces .
- Difference between a Value Type and a Reference Type
- System level Exceptions Vs Application level Exceptions
- Difference between sub-procedure and function
- What does the term immutable mean
- What does the keyword static mean
- this.close() Vs Application.Exit()
- Difference between a.Equals(b) and a == b
- Difference between Hashtable and Dictionary
- Difference between Exception and Error
- C# Dictionary Versus List Lookup Time
- Difference between the Class and Interface in C#