Chapter    12

Inheritance

When you write an object-oriented program, the classes and objects you create have relationships with one another. They work together to make your program do its thing.

Two aspects of OOP are most important when dealing with relationships between classes and objects. The first is inheritance, the subject of this chapter. When you create a new class, it’s often useful to define the new class in terms of its differences from an already existing class. Using inheritance, you can define a class that has all the capabilities of a parent class: it inherits those capabilities. You can have a general class called Automobile, for example, that defines a vehicle for operation on roads, typically with four wheels, such as a truck ...

Get Learn Swift on the Mac: For OS X and iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.