Difference between Multiple inheritance and interface
Interface
1.When a class inherits only the signatures of the functions from its corresponding base class, then it is interface
2.Interfaces like classes define a set of properties methods and events. But unlike classes interfaces do not provide implementation
3.C# support Interface instead of multiple inheritance.
Multiple inheritance
1. When a class is derived from more than one base class in such a way that it will inherit all its members to its corresponding derived class, then it is implementation inheritance.
2. C# doesn't support Multiple Inheritance
3.In C#, we can only inherit from one class but multiple interfaces
Example:-
interface ICustomerCollection
{
void Add(string customerName);
void Delete(string customerName);
}
class CustomerCollection : ICustomerCollection
{
public void Add(string customerName)
{
/*Customer collection add method specific code*/
}
public void Delete(string customerName)
{
/*Customer collection delete method specific code*/
}
}
class MyUserControl: UserControl, ICustomerCollection
{
CustomerCollection _customerCollection=new CustomerCollection();
public void Add(string customerName)
{
_customerCollection.Add(customerName);
}
public void Delete(string customerName)
{
_customerCollection.Add(customerName);
}
}
Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator