Run »
using System; namespace MyApplication { class Animal // Base class (parent) { public void animalSound() { Console.WriteLine("The animal makes a sound"); } } class Pig : Animal // Derived class (child) { public void animalSound() { Console.WriteLine("The pig says: wee wee"); } } class Dog : Animal // Derived class (child) { public void animalSound() { Console.WriteLine("The dog says: bow wow"); } } class Program { static void Main(string[] args) { Animal myAnimal = new Animal(); // Create a Animal object Animal myPig = new Pig(); // Create a Pig object Animal myDog = new Dog(); // Create a Dog object myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } } }
The animal makes a sound
The animal makes a sound
The animal makes a sound