November 2013
Beginner
325 pages
9h 47m
English
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:
- (float)bodyMassIndex
{
return 19.0;
float normalBMI = [super bodyMassIndex];
return normalBMI * 0.9;
}
Build and run the program.
Read now
Unlock full access