super

When overriding a method, a subclass can build on the implementation of its superclass rather than replacing it wholesale. What if you decided that employees get 10% off their BMI as calculated in BNRPerson’s implementation? It would be convenient to call BNRPerson’s version of bodyMassIndex and then multiply the result by 0.9. To do this, you use the super directive. Try it in BNREmployee.m:

-​ ​(​f​l​o​a​t​)​b​o​d​y​M​a​s​s​I​n​d​e​x​
{​
 ​ ​ ​ ​r​e​t​u​r​n​ ​1​9​.​0​;​
 ​ ​ ​ ​f​l​o​a​t​ ​n​o​r​m​a​l​B​M​I​ ​=​ ​[​s​u​p​e​r​ ​b​o​d​y​M​a​s​s​I​n​d​e​x​]​;​
 ​ ​ ​ ​r​e​t​u​r​n​ ​n​o​r​m​a​l​B​M​I​ ​*​ ​0​.​9​;​
}​

Build and run the program.

Get Objective-C Programming: The Big Nerd Ranch Guide 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.