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. lintcode - 恢复ip地址

    class Solution { public: /* * @param s: the IP string * @return: All possible valid IP addresses */ ...

  2. 利用Shell脚本实现远程MySQL自动查询

    下面这个脚本是一个简单用来执行远程数据库查询的命令,相信大家都能看得懂,这对于有些需要每天自动检查数据库或是执行某些语句的兄弟,是很有帮助的,只要稍加修改就可以 #!/bin/shHOST=192.1 ...

  3. java不可见字符 trim

    trim()的作用去掉前后的空格,  但是解析excel,出现一个字符串trim之后还是有”空格“ 做了一下实验,原来一些不可见的字符不一定是“空格”, trim()也去不掉, 只能自己写方法了

  4. [2019BUAA软工]团队项目选择

    Team V1 项目分析 写在前面 项目 内容 这个作业属于哪个课程 BUAA2019软件工程 这个作业的要求在哪里 团队项目选择 参考链接 如何提出靠谱的项目建议 NABCD 我们在这个课程的目标是 ...

  5. Python中的None与 NULL(即空字符)的区别

    None是Python的特殊类型,NoneType对象,它只有一个值None. 它不支持任何运算也没有任何内建方法. None和任何其他的数据类型比较永远返回False. None有自己的数据类型No ...

  6. 【Java】Java中的Collections类——Java中升级版的数据结构【转】

    一般来说课本上的数据结构包括数组.单链表.堆栈.树.图.我这里所指的数据结构,是一个怎么表示一个对象的问题,有时候,单单一个变量声明不堪大用,比如int,String,double甚至一维数组.二维数 ...

  7. [转]jQuery Mobile动态刷新页面样式

    本文转自:http://blog.csdn.net/zht666/article/details/8560765 当我们使用Ajax或者javascript动态在页面上添加元素后,如添加select控 ...

  8. 35、XPath的使用示例

    使用Xpath获取页面元素 [参见W3C官网说明] http://www.w3school.com.cn/xpath/xpath_syntax.asp   以下Xpath路径都是获取下面地址的元素   ...

  9. C#取得程序的根目录以及判断文件是否存在

    一:获取根目录的方法 取得控制台应用程序的根目录方法方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDo ...

  10. Hack Knowledges

    XSS(Cross-Site Scripting) Hacker PC -- upload XSS script to Web Server --> User PC Request for th ...