Virtual method and override
In this article we'll:
- Add a virtual method called "MakeSound" to the
Animal
base class. - Override the
MakeSound
method with specific implementation for the Cat and the Dog Classes.
Animal Class
class Animal
{
public virtual void MakeSound()
{
}
}
Dog Class
class Dog:Animal
{
public override void MakeSound()
{
MessageBox.Show("Hav Hav");
}
}
Cat Class
class Cat:Animal
{
public override void MakeSound()
{
MessageBox.Show("Miaoo");
}
}
Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com