CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
//the Pet class is an abstract class, i cant be instantiated. if you try, compiler will complain
class Pet
{
public:
string Name;
//Constructor, is only called by base classes
Pet(string name)
{
Name = name;
}
//this method makes the class an abstract class, it has no implementation, derived classes are supposed to do this
virtual void makeNoise() = 0;
};
class Cat : public Pet
{
public:
//Constructor, base class constructor is called for name assignment
Cat(string name) : Pet(name) {}
//the Cat-Class needs to implement the makeNoise function to work
void makeNoise()
{
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run