首页 > Windows开发 > 详细

C#第二单元 11题

时间:2017-09-17 23:20:05      阅读:271      评论:0      收藏:0      [点我收藏+]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Txst_2._1
{
    class Animal
    {
        private Boolean m_sex;
        private string m_sound;
        public Animal()
        {
            m_sex = false;
            m_sound = "Howl...";
        }
        public bool Sex
        {
            get { return m_sex; }
            set { m_sex = value; }
        }
        public string Sound
        {
            get { return m_sound; }
            set { m_sound = value; }
        }
        public virtual string Roar()
        {
            return "Animal" + m_sound;
        }
    }
    class Dog : Animal
    {
        public Dog()
        {
            Sex = true;
            Sound = "Wow...";
        }
        public override string Roar()
        {
            return "Dog:" + Sound;
        }
    }
    class Cat : Animal
    {
        public Cat()
        {
            Sound = "Miaow...";
        }
        public override string Roar()
        {
            return "Cat:" + Sound;
        }
    }
    class Cow : Animal
    {
        public Cow()
        {
            Sound = "Moo...";
        }
        public override string Roar()
        {
            return "Cow:" + Sound;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Animal animal;
            animal = new Dog();
            Console.WriteLine(animal.Roar());
            Console.WriteLine();
            animal = new Cat();
            Console.WriteLine(animal.Roar());
            Console.WriteLine();
            animal = new Cow();
            Console.WriteLine(animal.Roar());
            Console.WriteLine();
            Console.Read();
        }
    }
}

技术分享

C#第二单元 11题

原文:http://www.cnblogs.com/aa1111/p/7538441.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!