public static void Showcase(Animal a) { // This has the same functionality as Animal x = new Dog() // if a dog is passed in. Console.WriteLine("Animal showcase"); a.Talk(); a.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); }