官术网_书友最值得收藏!

Inheritance

Inheritance in programming is the same as in real life. A girl inherits from her mother, who inherits from her mother, and so on. The following diagram shows inheritance in the real world and how it relates to OOP:

Inheritance examples

On the left-hand side of the preceding diagram, a Grandmother passes down traits to the Daughter, who passes down traits to the Granddaughter. So, the Granddaughter inherits from both the Daughter and Grandmother. The same inheritance concept applies to our Bicycle class, which inherits from both the Two-Wheeled class and the Vehicle class. This is a powerful schema as it avoids class bloating. As an example, if the Vehicle class has data elements such as year, make, and model, those elements are automatically part of the Two-Wheeled and Bicycle classes. We will see an example of this later on in this chapter.

主站蜘蛛池模板: 治多县| 乐东| 嵩明县| 当阳市| 潼关县| 二连浩特市| 花莲市| 翁牛特旗| 修武县| 平南县| 眉山市| 贺兰县| 洪湖市| 河池市| 剑川县| 秦安县| 秦安县| 隆昌县| 博白县| 延津县| 卓尼县| 南木林县| 定西市| 营山县| 临桂县| 玛沁县| 开平市| 晋州市| 柯坪县| 遂川县| 霍州市| 清徐县| 常德市| 彭阳县| 紫金县| 九龙城区| 中山市| 巴林左旗| 瑞丽市| 准格尔旗| 涡阳县|