Are class methods inherited?

When I define a new class inheriting from NSObject:

@interface Photo : NSObject
{
    NSString* caption;
    NSString* photographer;
}

@property NSString* caption;
@property NSString* photographer;

@end

- all class methods (e.g. alloc) in NSObjectinherited by the new class Photo?

+5
source share
1 answer

Yes, it Photocan use any method / property / ivar / etc (with the exception of those declared iVars @private) NSObjectwhen subclassing NSObject:

Photo *myPhoto;
myPhoto = [[Photo alloc] init];
// ... Do some myPhoto stuff ...
NSLog(@"Photo object: %@", myPhoto);
NSLog(@"Photo description: %@", [myPhoto description]);
NSLog(@"Photo caption: %@", [myPhoto caption]);
NSLog(@"Photo photographer: %@", [myPhoto photographer]);

More on @privateSO Question: what-does-private-mean-in-objective-c

NSObject Class reference

+5
source

All Articles