Inheritance

When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability.
    
It is used to achieve runtime polymorphism.

Sub class - Subclass or Derived Class refers to a class that receives properties from another class.
Super class - The term "Base Class" or "Super Class" refers to the class from which a subclass inherits its properties.
Reusability - As a result, when we wish to create a new class, but an existing class already contains some of the code we need, 
we can generate our new class from the old class thanks to inheritance. This allows us to utilize the fields and methods of the 
pre-existing class.

Ex:-

#include <iostream>
using namespace std;

// Superclass (Base class)
class Animal {
public:
    // Method in the base class (Superclass)
    void eat() {
        cout << "This animal is eating." << endl;
    }
};

// Subclass (Derived class) that inherits from Animal
class Dog : public Animal {
public:
    // Method specific to the derived class (Subclass)
    void bark() {
        cout << "The dog is barking." << endl;
    }
};

int main() {
    // Creating an object of the subclass Dog
    Dog myDog;

    // Calling the method from the base class Animal
    // This demonstrates inheritance: Dog inherits eat() from Animal
    myDog.eat(); 

------------------------------------------------------------------------------------------------------------------------------------

Polymorphism
    
When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently,
    to draw something e.g. shape or rectangle etc.

Different situations may cause an operation to behave differently. The type of data utilized in the operation determines the behavior.
    
#include <iostream>

// Base class
class Animal {
public:
    virtual void makeSound() {
        std::cout << "The Animal makes a sound" << std::endl;
    }
};

// Derived class Dog
class Dog : public Animal {
public:
    void makeSound() override {
        std::cout << "Dog barks!" << std::endl;
    }
};

// Derived class Cat
class Cat : public Animal {
public:
    void makeSound() override {
        std::cout << "Cat meows!" << std::endl;
    }
};

// Main function to demonstrate polymorphism
int main() {
    // Create base class object
    Animal* animal = new Animal();
    Animal* dog = new Dog();  // Create Dog object but point with Animal pointer
    Animal* cat = new Cat();  // Create Cat object but point with Animal pointer

    // Call makeSound for each object
    animal->makeSound();  // Calls base class method
    dog->makeSound();     // Calls Dog's method due to polymorphism
    cat->makeSound();     // Calls Cat's method due to polymorphism

    // Clean up
    delete animal;
    delete dog;
    delete cat;

    return 0;
}

Enables Polymorphism: The virtual keyword is essential for enabling polymorphism in C++. It ensures that when you use a base class
    pointer to refer to a derived class object, the derived class's overridden method will be called at runtime (dynamic dispatch),
    not the base class method (static binding).

Flexible and Extensible Design: It allows you to create more flexible and extensible designs where new derived classes can override
    base class behavior without needing to modify existing code.

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: