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 ...

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.