Professional Documents
Culture Documents
Single Inheritence
Single Inheritence
#include <string>
// Base class
class Animal {
private:
std::string name;
public:
void eat() {
void sleep() {
};
// Derived class
private:
std::string breed;
public:
// Constructor for Dog class, calling the base class constructor explicitly
void bark() {
void sleep() {
std::cout << "The dog named " << getName() << " is sleeping." << std::endl;
void displayBreed() {
};
int main() {
myDog.eat();
myDog.bark();
myDog.displayBreed();
return 0;