Sunday, 18 August 2013

Why can I call a subclass method with a superclass pointer in Objective-C?

Why can I call a subclass method with a superclass pointer in Objective-C?

I have two classes, NSMom and NSSon. NSMom is NSSon's super class.
NSMom *mom = [[NSSon alloc] init];
is valid as long as I call NSMom's methods, right?
But how come that mom pointer can call one of NSSon's methods (which is
defined as an additional method in the subclass)?

No comments:

Post a Comment