#include "stdafx.h"
using namespace System;
ref class Animal{
public:
virtual void Speak (){
Console::WriteLine("Animal");
}
};
ref class Dog : public Animal{
public:
virtual void Speak() override{
Console::WriteLine("Dog");
}
};
ref class Puppy : public Dog{
public:
virtual void Yip() = Dog::Speak
{
Console::WriteLine("Puppy");
}
};
ref class Cat : public Animal{
public:
virtual void Speak() new
{
Console::WriteLine("Cat");
}
};
ref class Tiger : public Cat{
public:
virtual void Growl() = Animal::Speak, Cat::Speak
{
Console::WriteLine("Tiger");
}
};
void main()
{
array^ animals = gcnew array {
gcnew Animal(),
gcnew Dog(),
gcnew Puppy(),
gcnew Cat(),
gcnew Tiger()
};
for each ( Animal ^a in animals){
a->Speak();
}
Console::WriteLine();
Animal^ cat1 = gcnew Cat();
Cat^ cat2 = gcnew Cat();
Cat^ tiger = gcnew Tiger();
cat1->Speak();
cat2->Speak();
tiger->Speak();
}