Difference b/w multiple inheritance and Interface

Posted by Kalaikathiravan under DotNetFunda.Com on 11/5/2012 | Points: 10 | Views : 6891 | Status : [Member] | Replies : 5
What is the Difference between Multiple inheritance and interface Please tell me friends




Responses

Posted by: Rajesh081725 on: 11/5/2012 [Member] Bronze | Points: 25

Up
0
Down
Interface is a contract that defines the signature of the functionality. So if a class is implementing a interface it says to the outer world, that it provides specific behavior. Example if a class is Interface Read More..

Interface support multiple inheritance
Interface does'n contains Cunstructors
An interface Contains only incomplete member (signature of member)
An interface cannot have access modifiers by default everything is assumed as public
Member of interface can not be Static
Class inheritance represents an "is-a" relationship, e.g., a Tank is a Vehicle. If your situation doesn't at least meet this, choose interface over inheritance.

In C#, you can only inherit from one class but multiple interfaces. This would be yet another reason to choose interface over inheritance.

http://stackoverflow.com/questions/6188827/inheritance-vs-interface-in-c-sharp

Thanks & Regards,
Rajesh Kumar,
9962038582.

Time is Gold
Thanks & Regards,
Rajesh Kumar,
9962038582.

Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajesh081725 on: 11/5/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.dotnetfunda.com/articles/article1185-multiple-inheritance-in-csharp.aspx

Thanks & Regards,
Rajesh Kumar,
9962038582.



Time is Gold
Thanks & Regards,
Rajesh Kumar,
9962038582.

Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 11/6/2012 [Member] Bronze | Points: 25

Up
0
Down
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

Posted by: Muhsinathk on: 11/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Please mark as answer if it helpful to you..That helps others who search the same..

Kalaikathiravan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response