Â
In this program, we are going to Learn Runtime polymorphism in C++ Programming Language.Â
Â
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream> using namespace std; class Animal { public: string color = "Black"; }; class Dog : public Animal { public: string color = "Grey"; }; int main() { Animal d; d = Dog(); cout << d.color; return 0; } //.......Coded by RISHAB NAIR
The Code given below can be used in Turbo Compilers: -
#include <iostream.h>
#include <conio.h>
class Animal
{
public:
char *color[10];
Animal()
{
*color = "Black";
cout << *color;
}
};
class Dog : public Animal
{
public:
char *color[10];
Dog()
{
*color = "Grey";
cout << *color;
}
};
void main()
{
clrscr();
Animal d;
d.color;
getch();
}
//.......Coded by RISHAB NAIR
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP