#include <iostream>
#include <string>
class Animal {
protected:
std::string name;
public:
Animal(const std::string& _name) : name(_name) {}
void eat() {
std::cout << name << " is eating." << std::endl;
}
};
class Dog : public Animal {
public:
Dog(const std::string& _name) : Animal(_name) {}
void bark() {
std::cout << name << " says Woof!" << std::endl;
}
};
int main() {
Dog myDog("Buddy");
myDog.eat(); // Inherited from Animal
myDog.bark(); // Specific to Dog
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: