1. Achieve page effects
2. Create a base class or superclass (parent class)
1 namespace small animals in the forest in a happy life 2 {3 Public Abstract class Animal// Animal class 4 {5public Abstractvoid Movement (); // How to exercise 6 }7 }
3. Create a derived class (Roe Class)
namespace small animals in the forest in a happy life { public class// derived class derived from base class { Publicoverridevoid Movement ()/// Parent class method { Console.WriteLine (" fish swim in the water! ") " ); } }}
4. Create a derived class (dog subclass)
1 namespacesmall animals in the forest in a happy life2 {3 Public classDog:animal4 {5 Public Override voidMovement ()6 {7Console.WriteLine ("the dog is running on the ground!");8 }9 }Ten}
5. Create a derived class (bird subclass omitted)
6.Main method
1 namespacesmall animals in the forest in a happy life2 {3 class Program4 {5 Static voidMain (string[] args)6 {7Console.WriteLine ("small animals in the forest in a happy life!");8 Console.WriteLine ();9Animal father =NewBird ();TenAnimal Father2 =NewDog (); OneAnimal Father3 =NewFish (); A Father3. Movement (); - Father2. Movement (); - father. Movement (); the console.readline (); - } - } -}
Abstract methods to achieve polymorphism ___ the animals in the forest in a happy life