类的继承

就一个":"  冒号。

类的继承,主要目的是代码的重用。另外,通过类的继承,代码有清晰的组织关系。

子类:父类   派生类:基类 

看代码

class Animal
    {
        public int weight;
        public int age;

        public Animal()
        {
            Console.WriteLine("动物 的构造方法");
        }
        public Animal(string n ,int w )
        {
            name = n; weight = w;
        }
        public void Sleep() { Console.WriteLine("动物睡觉"); }

        private string name;

        protected string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

上面的类是动物 基类

 class Wolf : Animal
    {
        public Wolf()
        {
            Console.WriteLine("狼 的构造方法");
        }
        public Wolf(string n, int w)
            : base(n,w)
        {            
                   
        }
        public void Eat()
        {

        }
    }
原文地址:https://www.cnblogs.com/imxh/p/2443322.html