In Objective-C, each new class is derived from a class that already exists. The
Car class described in Listings 2-3 through 2-7 inherits from
NSObject, the root class of the Objective-C class tree. Each subclass adds or modifies state and behavior that it inherits from its parent, also called its “superclass.” The
Car class adds several instance variables and methods to the vanilla
NSObject it inherits from.
HybridCar class inherits from
Car and adds functionality to calculate the distance the car can travel until empty, based on the MPG that the hybrid car is capable of. Listings 2-9 and 2-10 show one possible way to implement the
HybridCar class. The sample code for this chapter contains a project with the code ...