zoukankan      html  css  js  c++  java
  • 类的继承

    就一个":"  冒号。

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

    子类:父类   派生类:基类 

    看代码

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

            }
        }
  • 相关阅读:
    npm --save-dev 与 --save 的区别
    Vue 简单实例 购物车2
    Vue 简单实例 购物车1
    node.js富文本编辑器
    使用jquery操作session
    浏览器窗口之间传递数据
    批量修改文件编码格式
    具有动态效果的响应式设计
    Ajax请求全局配置
    html实体转换
  • 原文地址:https://www.cnblogs.com/imxh/p/2443322.html
Copyright © 2011-2022 走看看