zoukankan      html  css  js  c++  java
  • 2.1,11

    namespace Txst2_1
    {
        class Animal
        {
            private Boolean m_sex;
            private int m_age;
            public bool Sex
            {
                get { return m_sex; }
    set { m_sex = false; }
            }
            public int  Age
            {
                get { return m_age; }
                set { m_age = value; }
            }
            public virtual string Introduce()
            {
                if (Sex == true)
                    return "This is a male Animal";
                else
                    return "This is a female Animal";
            }
        }
        class Dog:Animal
        {
            public Dog()
            {
                Sex = true;
            }
            public override string Introduce()
            {
                if (Sex == true)
                    return "This is a male Dog";
                else
                    return "This is a female Dog";
            }
        }
        class Cat:Animal
        {
            public override string Introduce()
            {
                if (Sex == true)
                    return "This is a male Cat";
                else
                    return "This is a female Cat";
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Animal ani = new Animal();
                Console.WriteLine(ani.Introduce());
                Animal dog = new Dog();
                Console.WriteLine(dog.Introduce());
                Animal cat = new Cat();
                Console.WriteLine(cat.Introduce());
                Console.Read();
            }
        }
    }

    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();         }     } }

  • 相关阅读:
    [再寄小读者之数学篇](2014-10-27 无穷多个无穷小量相乘还是无穷小量么?)
    华中师范大学2012年数学分析考研试题参考解答
    本科时的课程与成绩
    2014 年第六届全国大学生数学竞赛预赛数学类试题参考答案
    [家里蹲大学数学杂志]第322期赣南师范学院数学竞赛培训第11套模拟试卷
    [再寄小读者之数学篇](2014-10-18 利用 Lagrange 中值定理求极限)
    和马有关的成语
    PL/pgSQL学习笔记之一
    PostgreSQL的 initdb 源代码分析之二十五
    PostgreSQL的 initdb 源代码分析之二十四
  • 原文地址:https://www.cnblogs.com/xuanchen/p/7538425.html
Copyright © 2011-2022 走看看