zoukankan      html  css  js  c++  java
  • test2-11

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

    namespace Test2_11
    {
    class Animal
    {
    private bool m_sex;
    private string m_sound;
    public Animal()
    {
    m_sex = false;
    m_sound="HOW1...";
    }
    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 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;
    }
    }
    }

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

    namespace Test2_11
    {
    class Program
    {
    static void Main(string[] args)
    {
    Animal animal = new Animal();
    Dog d = new Dog();
    Cat c = new Cat();
    Cow w = new Cow();
    animal = d;
    Console.WriteLine(animal.Roar());
    animal = c;
    Console.WriteLine(animal.Roar());
    animal = w;
    Console.WriteLine( animal.Roar());
    }
    }
    }

  • 相关阅读:
    O'Reilly总裁提姆奥莱理:什么是Web 2.0
    在MFC程序中显示JPG/GIF图像
    VC窗体设计集锦
    VxWorks使用说明书
    关于双缓冲绘图之二
    如何将EVC4工程升级到VS.NET2005工程
    某个正在运行的程序的CPU占用率
    如何去掉回车键和取消键
    探索NTFS
    ARM上的C编程
  • 原文地址:https://www.cnblogs.com/YuJiaJia/p/7507347.html
Copyright © 2011-2022 走看看