A derived class inherits all of the members of a base class except for its constructors.

You must define a constructor in a derived class unless the base class has defined a default (parameterless) constructor.  If you don’t define a constructor in the derived class, the default constructor in the base class is called implicitly.

When you define a constructor in a derived class, you can call a constructor in the base class by using the base keyword.

Here’s an example:

 public class Dog
{
public string Name { get; set; }
public int Age { get; set; } public Dog(string name, int age)
{
Name = name;
Age = age;
}
} public class Terrier : Dog
{
public string Attitude { get; set; } // Call the Name/Age constructor in the base class
public Terrier(string name, int age, string attitude)
: base(name, age)
{
Attitude = attitude;
}
}

原文地址:#330 - Derived Classes Do Not Inherit Constructors

【转载】#330 - Derived Classes Do Not Inherit Constructors的更多相关文章

  1. How can I protect derived classes from breaking when I change the internal parts of the base class?

    How can I protect derived classes from breaking when I change the internal parts of the base class? ...

  2. [C++] OOP - Base and Derived Classes

    There is a base class at the root of the hierarchy, from which the other class inherit, directly or ...

  3. Virtual functions in derived classes

    In C++, once a member function is declared as a virtual function in a base class, it becomes virtual ...

  4. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  5. C# to IL 4 Keywords and Operators(关键字和操作符)

    Code that is placed after the return statement never gets executed. In the first programgiven below, ...

  6. (转) Friendship and inheritance

    原地址: http://www.cplusplus.com/doc/tutorial/inheritance/ Friend functions In principle, private and p ...

  7. 转载:《TypeScript 中文入门教程》 4、类

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 介绍 传统的JavaScript程序使用函数和基于原型的继承来创建可重用的组件,但这对 ...

  8. C# - Abstract Classes

     Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, ...

  9. Python Tutorial 学习(九)--Classes

    ## 9. Classes 类 Compared with other programming languages, Python's class mechanism adds classes wit ...

随机推荐

  1. hdu1387 模拟队列

    Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  2. jq得到总价

    <html><head> <title></title> {load href="/static/js/jquery-1.9.1.min.js ...

  3. Java对象排序两种方法

    转载:https://blog.csdn.net/wangtaocsdn/article/details/71500500 有时候需要对对象列表或数组进行排序,下面提供两种简单方式: 方法一:将要排序 ...

  4. 读书印记 - 《文革前的邓小平:毛XX的副帅》

    开始看才发现这居然是本学术著作,阅读难度系数比小说.传记要很多,相比于小说的人物心理.传记的故事套路,这本书的基本写法是举一大坨材料来描述当时的事实然后稍微发表一点学术观点.....我对这个内容本身挺 ...

  5. codeforces之4.1学习记录

    记录一些之前没见过的代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF ...

  6. php数组·的方法1-数组的操作

    //range() 创建一个含指定范围的数组 可设置间隔 var_dump(range(1, 9, 2)); echo '<br>'; //array_combine() 合并两个数组创建 ...

  7. JavaScript 将数组中具有相同值的对象 取出组成新的数组

    var arr=[{name:2,id:3},{name:2,id:4},{name:3,id:5},{name:3,id:6},{name:1,id:1},{name:1,id:2}]; // 传入 ...

  8. ES6和ES5中的this指向问题

    不多逼逼 直接上代码: var name = "window"; var obj = { name: 'obj', //普通函数 one: function(){ console. ...

  9. Turn.js 实现翻书效果

    Turn.js的官方网址: http://www.turnjs.com/ 官网上运行demo如下,大家主要关注是 属性使用: <!DOCTYPE html> <html> &l ...

  10. [转]关于Jquery的DataTables里TableTools的应用

    本文转自:http://147068307.iteye.com/blog/1700516 最近在产品中使用了TableTools这个工具,主要用来实现导出和复制功能. 但是在实际的运用中出现了以下相关 ...