- C# 7 and .NET Core 2.0 Blueprints
- Dirk Strauss Jas Rademeyer
- 240字
- 2021-08-27 19:55:26
Inheritance
The ability to be able to create your own classes that reuse, extend, and modify the behavior that the base class defines is called inheritance. Another important aspect to understand is that a derived class can only directly inherit a single base class.
Does this then mean that you can only inherit the behavior defined in a single base class? Well, yes and no. Inheritance is transitive in nature.
To explain this, imagine that you have three classes:
- Person
- Pedestrian
- Driver
The Person class is the base class. Pedestrian inherits from the Person class and therefore Pedestrian inherits the members declared in the Person class. The Driver class inherits from the Pedestrian class and therefore Driver inherits the members declared in Pedestrian and Person:

This is what is meant when we say that inheritance is transitive. You can only inherit from a single class, but you get all the members that the class you inherit from, inherits itself. You can only inherit from a single class, but you get all the members that the class you are inheriting from, inherits from its base class. Put another way, the Driver class can only inherit from a single base class (in the preceding image, the Pedestrian class). This means that because the Pedestrian class inherits from the Person class, and the Driver class inherits from the Pedestrian class, that the Driver class also inherits the members in the Person class.
- Data Visualization with D3 4.x Cookbook(Second Edition)
- Cocos2D-X權威指南(第2版)
- DevOps with Kubernetes
- React Native Cookbook
- Unity 2020 Mobile Game Development
- aelf區塊鏈應用架構指南
- Object-Oriented JavaScript(Second Edition)
- PLC編程及應用實戰
- HTML5 and CSS3 Transition,Transformation,and Animation
- Node.js全程實例
- Java程序設計入門
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- Spring Boot實戰
- Test-Driven JavaScript Development
- OpenMP核心技術指南