public static void ShowTime(Dog d) { Console.WriteLine("Dog showcase"); d.Talk(); d.disp(); }
public static void Polymorphism() { Console.WriteLine("\nPOLYMORPHISM:"); Animal a = new Animal("a"); // Animal reference that refers to an animal Animal b = new Dog("b"); // Animal reference that refers to a dog Dog c = new Dog("c"); // Dog reference that refers to a dog // Dog d = (Dog)b; a.Talk(); // Base class virtual a.disp(); // Base class disp b.Talk(); // Derived class override b.disp(); // Base class disp c.Talk(); // Derived class override c.disp(); // Derived class new Console.WriteLine(); Animal.Showcase(a); Animal.Showcase(b); Animal.Showcase(c); Dog.ShowTime((Dog)b); Dog.ShowTime(c); }