15 Inheritance
Inheritance is an object-oriented principle you can use to define hierarchical relationships between types. In this chapter you will use inheritance to share data and behavior between related classes.
To get a handle on inheritance, consider an example outside of programming. Cars and trucks have much in common: They each have wheels, an engine, etc. They also have some different features. Using inheritance, you could define the things that they have in common in a shared class, Automobile, so that you do not have to implement the steering, engine, and so on in both Car and Truck. Car and Truck would inherit those shared features, making slight modifications as necessary, and each would then define its own unique ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access