Definition P: - PabitraBhandari/2143-OOP-Bhandari GitHub Wiki
Polymorphism:
Definition:
"Polymorphism" itself means having many forms. It can be defined as the ability of a function to be appear in different forms.
In C++, There are two types of polymorphism:
- Run-time Polymorphism
- Compile-time Polymorphism
Image:
Example Code:
// Base class
class Animal {
public:
void Sound() {
cout << "The animal makes a sound"<<endl;
}
};
// Derived class
class Bob : public Animal {
public:
void Sound() {
cout << " wee wee"<<endl;
}
};
// Derived class
class Peet : public Animal {
public:
void Sound() {
cout << " bow wow"<<endl;
}
};