================Program主入口================

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

namespace PersonDemo2
{
    class Program
    {
        static void Main(string[] args)
        {
          // Person p = new Person() { Name = "大圣" };
          // p.Speak("only you");

          // Stu s = new Stu();
          // //Person p = new Person() { Gender=Gender.Man, Hobby="吃鸡翅膀", Name="大圣" };
          //// s.ShowInfo();
          // s.Speak("曾经有........三个字");


           Person p = new Stu();
           p.Study();
           p.Speak("xx");

         // Stu s = new Person();

     

        }
    }
}

 

=======================Person类==========================

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

namespace PersonDemo2
{
    /// <summary>
    /// 性别
    /// </summary>
    public enum Gender
    {
        Female,Man
    }

   public class Person
   {
       #region 
       protected string name;
       private Gender gender;
       private string hobby;
       protected int age;
       #endregion

       public Person()
       {
       }

       public string Name
       {
           get { return name; }
           set { name = value; }
       }
       public Gender Gender
       {
           get { return gender; }
           set { gender = value; }
       }
       public string Hobby
       {
           get { return hobby; }
           set { hobby = value; }
       }

       public virtual void Speak(string msg)
       {
           Console.WriteLine(name+"说"+msg);
       }

       public void ShowInfo()
       {
           Console.WriteLine("{0} {1} {2} {3}",name,gender,hobby,age);
       }

       public virtual void Study()
       {
           Console.WriteLine("so bad!");
       }
   }
}

 

 

=======================Student类==========================

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

namespace PersonDemo2
{
    /// <summary>
    /// 1 调用父类的属性和方法(公开的 protected(字段))
    /// 2 调用父类的构造函数 分配内存空间
    /// </summary>
    class Stu:Person,IFlyable
    {
        public Stu()
        {
            
        }

        public override void Speak(string msg)
        {
            Console.WriteLine(base.name+"说"+msg);
        }

        public void Study()
        {
            Console.WriteLine("good good study !day day up");
        }

        #region IFlyable 成员

        public void Fly()
        {
            Console.WriteLine("i can fly");
        }

        #endregion
    }
}

posted on 2016-08-31 15:08  遥望末班车  阅读(349)  评论(0)    收藏  举报