Headers and inheritance

A subclass has no access to its superclass’s class extensions. BNREmployee is a subclass of BNRPerson and imports its superclass’s header file, BNRPerson.h. Thus, BNREmployee knows about what is declared in BNRPerson’s header but knows nothing about anything that BNRPerson may have declared in a class extension.

For example, if you implemented a hasDriversLicense method in BNRPerson.m but declared it in a class extension rather than BNRPerson.h, then BNREmployee would not know that this method existed. If you tried to call it in BNREmployee.m:

B​O​O​L​ ​c​a​n​D​r​i​v​e​C​o​m​p​a​n​y​V​a​n​ ​=​ ​[​s​e​l​f​ ​h​a​s​D​r​i​v​e​r​s​L​i​c​e​n​s​e​]​;​

you would get an error from the compiler: No visible @interface declares the instance method hasDriversLicense.

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

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