码迷,mamicode.com
首页 > 其他好文 > 详细

2.11

时间:2017-09-19 00:13:18      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:ace   false   rgs   set   namespace   void   virtual   bsp   bool   

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

2.11

标签:ace   false   rgs   set   namespace   void   virtual   bsp   bool   

原文地址:http://www.cnblogs.com/hysu/p/7545454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!