Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are class methods inherited too?

When I define a new class inheriting from NSObject:

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

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

@end

are all the class methods (like alloc) in NSObject inherited by the new class Photo?

like image 286
ray Avatar asked Oct 26 '11 02:10

ray


1 Answers

Yes, Photo can use any method/property/ivar/etc (except for those iVars declared @private) of a NSObject when you subclass 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 about @private -> SO Question: what-does-private-mean-in-objective-c

NSObject Class Reference

like image 162
chown Avatar answered Sep 24 '22 05:09

chown