CSC307 Assignment Project
CSC307 Assignment Project
DEFINITION OF POLYMORPHISM
Here is an example:
class Animal {
public:
};
class Cat : public Animal {
public:
};
public:
};
int main() {
In this example, we have a base class Animal with a virtual function speak(). We
then define two derived classes Cat and Dog that override the speak() function. In
the main() function, we create three pointers of type Animal* that point to objects
of different types (Animal, Cat, and Dog). When we call the speak() function on
each of these pointers, the actual function that is called is determined at runtime
based on the type of the object being pointed to. This is an example of runtime
polymorphism in action.