super

What if you decided that all employees get an automatic 10% off their BMI as calculated in the Person’s implementation? You could, of course, retype the code in the Employee implementation, but it would be so much more convenient to call Person’s version of bodyMassIndex and multiply the result by 0.9 before returning it. To do this, you use the super directive. Try it in Employee.m:

#​i​m​p​o​r​t​ ​"​E​m​p​l​o​y​e​e​.​h​"​
@​i​m​p​l​e​m​e​n​t​a​t​i​o​n​ ​E​m​p​l​o​y​e​e​

@​s​y​n​t​h​e​s​i​z​e​ ​e​m​p​l​o​y​e​e​I​D​;​

-​ ​(​f​l​o​a​t​)​b​o​d​y​M​a​s​s​I​n​d​e​x​
{​
 ​ ​ ​ ​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​;​
}​

@​e​n​d​

Build and run the program.

To be precise, the super directive says Run this method, but start the search for its implementation at my superclass.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset