3
Reply

Difference between inheritance and polymorhism ?

sathish

sathish

May 21, 2009
31.4k
0

    Inheritance and Polymorphism are the two beasts of OOPs. Definition of Polymorphism: Mostly it is defined as 'To achieve multiple behaviours of the same variable' and it is achieved by using inheritance. So inheritance is the prerequisit of inheritance based Polymorphism. Difference between Inheritance and Polymorphism: In inheritance based polymorphism, common method(s) are defined in the base class and override them in the derived class with different implementation. So, now the challenge is to call the method of derived class with the base class object. To achieve the polymorphism, define an object variable of the base class and initialize it with a child class object. Whenever the method defined in the base class will be called, its implementation of child class will be called. Conclusion: In this way, we can build the better and scalable applications.

    May 26, 2009
    1

    Hi, Sathish
    This article clear all point regarding inheritance and polymorphism. Click to read article....

    Manish Tewatia
    August 12, 2010
    0

    Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse existing code. Through effective employment of reuse, you can save time in your programming. Inheritance is transitive in nature.
    There are two types of polymorphism:

    1.   Compile time polymorphism
    2.   Run time polymorphism.

    Compile Time Polymorphism

    Compile time polymorphism is method and operators overloading. It is also called early binding.

    In method overloading method performs the different task at the different input parameters.

    Runtime Time Polymorphism

    Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding.

    When overriding a method, you change the behavior of the method for the derived class.  Overloading a method simply involves having another method with the same prototype.

    Both inhertiance and polymorphism a corelated terms used with each other.

     


     

    Puran Mehra
    May 27, 2009
    0