Complete the code to declare a base class named Animal.
class [1] { public: void speak() { std::cout << "Animal sound" << std::endl; } };
The base class is named Animal. This is the class from which others can inherit.
Complete the code to declare a derived class Dog that inherits from Animal.
class Dog : public [1] { public: void speak() { std::cout << "Woof!" << std::endl; } };
The derived class Dog inherits from the base class Animal using public inheritance.
Fix the error in the code to call the base class speak() method inside the derived class Dog's speak() method.
class Dog : public Animal { public: void speak() { [1]::speak(); std::cout << "Woof!" << std::endl; } };
To call the base class method, use the base class name Animal followed by the scope resolution operator.
Fill both blanks to create a constructor in the derived class Cat that calls the base class constructor with a name parameter.
class Cat : public Animal { public: Cat(std::string [1]) : [2]([1]) {} };
The constructor parameter is name. The base class constructor Animal is called with this parameter.
Fill all three blanks to override the speak() method in the derived class Bird and call the base class speak() method.
class Bird : public [1] { public: void speak() override { [2]::[3](); std::cout << "Tweet!" << std::endl; } };
The derived class Bird inherits from Animal. To call the base class method, use Animal::speak().