Creating an object from a subclass doesn't mean a separate instance from the super class will be created too. You'll only have one object which is a ChildViewController
and a SuperViewController
at the same time.
When the above code is executed, the self
keyword references to the actual instance of ChildViewController
which is also, at the same time, an instance of SuperViewController
too.
And if you log the self
keyword in the subclass and its super class, you will notice that they actually point to the same object in memory.
P.S. You can try po (SuperViewController *) [[self mySession] delegate]
and you'll get what you expect.