(16)C#继承

继承格式

class 子类:父类
{
.......
}

1、子类能够继承父类所有的字段和方法。

class Program
    {
        class Father
        {
          public int a=1;
          public void b()
            {
                Console.WriteLine("父类方法");
            }
        }
        class Son:Father
            { 
         
            }
        static void Main(string[] args)
        {
            Son w = new Son();
            Console.WriteLine(w.a);//输出 1
            w.b();//输出 父类方法
        }       
    }

子类只能有一个父类。

 

posted @ 2016-07-03 09:54  富坚老贼  阅读(124)  评论(0编辑  收藏  举报