| 1. |
Write a short note on inheritance and polymorphism. |
|
Answer» 1. Inheritance: Inheritance is the process of creating new classes, called derived class, from existing or base classes. The derived class inherits all the capabilities of the base class. Using Inheritance some qualities of the base classes are added to the newly derived class, apart from its own features. Inheritance permits code reusability. The different types of inheritance are single inheritance, multilevel inheritance, multiple inheritance, hierarchical inheritance, and hybrid inheritance. 2. Polymorphism: The polymorphism is ability of an object to take more than one form in different instances. For example, one function name can be used for different purposes. Similarly, same operator can be used for different operations. There are of two types one is the “compile time polymorphism” and other one is the “run-time polymorphism”. The polymorphism is implemented using function overloading and operator overloading in C++. |
|