Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
#include
#include
using namespace std; // Base class class Animal { public: void animalSound() { cout << "The animal makes a sound \n"; } }; // Derived class class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee \n"; } }; // Derived class class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow \n"; } }; int main() { Animal myAnimal; Pig myPig; Dog myDog; myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); return 0; }
The animal makes a sound
The pig says: wee wee
The dog says: bow wow