Wednesday, October 27, 2010

Multiple Inheritance and Interfaces

When we say we inherit from a class, what is it that we actually inherit?

We inherit the state and behavior of the class. Properties and variables define the state of a class and methods define the behavior.

But when we talk about interfaces, do they have state and behavior?

They don't, as you can only define signatures in an interfaces. Any class implementing this interface must provide the behavior and can have dependent state.

It is very obvious that we implement an interface and not inherit from it.

Many modern languages have learned from the older languages and choose not to support multiple inheritance because of the problems that they have. C# for that instance does not provide multiple inheritance.

There is a misconception that interfaces can be used to implement multiple inheritance in C#. But this is not true, as they do not have anything (state or behavior) that can be inherited.

0 comments:

Post a Comment