• C#认证第二单元 11题


    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());
    animal = new Cat();
    Console.WriteLine(animal.Roar());
    animal = new Cow();
    Console.WriteLine(animal.Roar());
    Console.Read();
    }
    }
    }

    测试结果:

  • 相关阅读:
    jQuery 笔记
    centos 项目上线shell脚本
    linux关于用户密码家目录总结
    python 写了一个批量拉取文件进excel文档
    css 选择器/table属性/type 属性
    表单
    html table
    html超文本标记语言
    mysql数据库1
    mysql数据库
  • 原文地址:https://www.cnblogs.com/HCBC/p/7529024.html
Copyright © 2020-2023  润新知