I have the subclass Foo
of the class Bar
:
@interface Foo : Bar
{
- (void)methodName;
}
It has the methodName
method which overrides the Bar
class' method.
I have the object of the Foo
's superclass:
Bar *bar = [[Bar alloc] init];
Then I send the message to this object:
[bar methodName];
Why is the Foo
's implementation of the methodName
is executed instead of the Bar
's? This method's implementation in Foo
completely overrides the one in Bar
, it doesn't call [super methodName]
. Pretty obvious to me that if the object were of the subclass, the subclass' implementation would be called, but why is it executed when the message is sent to the object of superclass?
Thank you in advance.