/*
mom and daughter some properties of mom inherited to daughter

Inheritance
In C++, it is possible to inherit attributes and methods from one class to another.
We group the "inheritance concept" into two categories:

derived class (child) - the class that inherits from another class
base class (parent) - the class being inherited from
To inherit from a class, use the : symbol.

////////////////////////If you're not using virtual and method overriding, then it's simply inheritance://////////////////////////

In this case, the method from the base class is inherited by the derived class, and the derived
class uses the method as is, without changing its behavior.
The method is inherited and works exactly the same for both the base and derived class unless explicitly overridden.
Example without virtual (inheritance only):
*/

#include <iostream>
#include <string>

class Animal {
  public:
    void sound() {
        std::cout << "Some generic animal sound." << std::endl;
    }
};

class Dog : public Animal {
  // No overriding, simply inherits sound()
};

int main() {
    Dog myDog;
    myDog.sound();  // Calls the inherited sound() method: "Some generic animal sound."
    return 0;
}

/*
Here, the Dog class inherits the sound() method from the Animal class and uses it directly without modification. This is inheritance.
If you're using virtual and method overriding, then it's polymorphism:

Why And When To Use "Inheritance"?
- It is useful for code reusability: reuse attributes and methods of an existing
class when you create a new class.
*/



Embed on website

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