惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
博客园 - 叶小钗
A
About on SuperTechFans
Last Week in AI
Last Week in AI
量子位
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
博客园 - 司徒正美
博客园 - Franky
博客园 - 【当耐特】
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
J
Java Code Geeks

博客园 - 言午

Nopcommerce 二次开发2 Admin Nopcommerce 二次开发1 基础 Nopcommerce 二次开发2 WEB Nopcommerce 二次开发0 sqlce中不支持sp_rename修改表名 C#读取Excel遇到无法读取的解决方法 狼奔代码生成器 银行账户类 累 interface 抽象类 抽象方法 Message 多态(虚方法) 事件event 委托 代理 索引! 第五周作业 第四周作业 考试! 线程安全 二 线程安全 一
类的继承
言午 · 2012-04-12 · via 博客园 - 言午

就一个":"  冒号。

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

子类:父类   派生类:基类 

看代码

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()
        {

        }
    }