Abstract methods to achieve polymorphism ___ the animals in the forest in a happy life

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.