Search This Blog

Wednesday, August 12, 2020

Polymorphism and Inheritance in C++

          C++ Programming:-

 In this tutorial you will learn:-

Polymorphism

Polymorphism is that in which we can perform a task in multiple forms or ways. It is applied to the functions or methods. Polymorphism allows the thing to make a decision which sort of the function to implement at compile-time also as run-time.


Types of Polymorphism are:


1. Compile-time polymorphism (Method overloading)

2. Run-time polymorphism (Method Overriding)





Inheritance is the process of by which a replacement class is made that inherits the properties of the exist already class. It supports the concept of code reusability and reduces the length of the code in object-oriented programming.


Types of Inheritance are:


1. Single inheritance

2. Multi-level inheritance

3. Multiple inheritance

4. Hybrid inheritance

5. Hierarchical inheritance



Difference between Inheritance and Polymorphism:

S.NOInheritancePolymorphism
1.Inheritance is one in which a new class is created (derived class) that inherits the features from the already existing class(Base class).Whereas polymorphism is that which can be defined in multiple forms.


2.It is basically applied to classes.
Whereas it is basically applied to functions or methods.


3.Inheritance supports the concept of reusability and reduces code length in object-oriented programming.Polymorphism allows the object to decide which form of the function to implement at compile-time (overloading) as well as run-time (overriding).


4.Inheritance can be single, hybrid, multiple, hierarchical and multilevel inheritance.Whereas it can be compiled-time polymorphism (overload) as well as run-time polymorphism (overriding).

5.It is used in pattern designing.While it is also used in pattern designing.





Mr. abhijeet dwivedi

Developer

Hey, I'm Abhijeet

0 comments:

Post a Comment

If you have any doubt, please let me know