• 类的继承


    就一个":"  冒号。

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

    子类:父类   派生类:基类 

    看代码

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

            }
        }
  • 相关阅读:
    C++ Tr1中的正則表達式
    html中#include file的使用方法
    InstallShield12豪华版破解版下载|InstallShield下载|软件打包工具
    linux-多线程
    使用 ArcGIS Online和APP进行监控操作和数据采集
    西藏印象:时光篇
    西藏印象:夜色篇
    西藏印象:蓝白篇
    hex2bin
    使用openssl的aes各种加密算法
  • 原文地址:https://www.cnblogs.com/imxh/p/2443322.html
Copyright © 2020-2023  润新知