Test Polymorphism Virtual Functions
/* A Programmer's Introduction to C# (Second Edition) by Eric Gunnerson Publisher: Apress L.P. ISBN: 1-893115-62-3 */ // 01 - Object-Oriented Basics\Polymorphism and Virtual Functions // copyright 2000 Eric Gunnerson using System; public PolymorphismVirtualFunctions { public static void CallPlay(MusicServer ms) { ms.Play(); } public static void Main() { MusicServer ms = new WinAmpServer(); CallPlay(ms); ms = new MediaServer(); CallPlay(ms); } } public abstract class MusicServer { public abstract void Play(); } public class WinAmpServer: MusicServer { public override void Play() { Console.WriteLine("WinAmpServer.Play()"); } } public class MediaServer: MusicServer { public override void Play() { Console.WriteLine("MediaServer.Play()"); } }