.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ishaqulhasan
    New Member
    • Oct 2006
    • 1

    .net

    What is multiple inheritance?
    what is virtual Polymorphism?
  • tm123456789
    New Member
    • Nov 2006
    • 5

    #2
    You've picked two particularly large and complex topics for your questions, but I'll do my best to offer a high level answer:

    1. Multiple inheritance is a feature offered by some programming languages (C++ for example) that allows Types to be derived from two or more other Types.

    Essentially, this means that you can create new objects that inherit functionality from two or more objects. Thus, if you create a new object called MyObject and make it inherit from ObjectA and ObjectB then MyObject will be able to make use of any inheritable fields/methods defined in both ObjectA and ObjectB, at least thats the general principle.

    The majority of today's programming languages (such as C# and VB.Net) do not support multiple inheritance. Instead, C# and VB offer single inheritance with the option of implementing multiple interfaces.

    Interfaces define a Type, or put differently, they define a contract that a class must support if it implements the interface. Thus if an interface called MyInterface defines a method called MyMethod that accepts an Integer parameter and returns a Boolean, then any class that implements MyInterface must also implement a method (MyMethod) that accepts an Integer parameter and returns a Boolean.

    Note that interfaces provide no code implementation i.e. interface methods don't actually do anything - the object that implements the interface must provide the code. Interfaces are only used to ensure that an object can be handled in a guaranteed way.

    2. Putting the word Virtual aside for a minute...

    Polymorphism refers to substitutabilit y. It allows one type of object to be substituted by a completely different type of object. This is only allowed when it is guaranteed that the two different objects can be safely handled in the same way. Substitutabilit y can be achieved when different types of objects expose a common Type (either via inheritance or interface implementation) as part of their definition.

    Thus, interfaces and inheritance (whether single or multiple) enable polymorphism.

    Marking a class method Virtual (in C#) means that any derived classes can override the code implementation for themselves if they so wish.

    Hope this makes things a little clearer...

    Comment

    Working...