basic inheritance

If the public method is NOT over-ridden, your class extends the hierarchy, then call the public method, you’ll use the public method declared FARTHEST from you

Say you have a Base class with a public method called “publicMethod”

Then, you have a Child1 class that derives from Base class. It does not over-ride publicMethod in Base class.

Then, you have a Child2 class that derives from Child1 class.

When you go:

It will call on publicMethod in the Base class.

If the public method IS over-ridden, your class extends the hierarchy, then call the public method, you’ll use the public method declared CLOSEST to you

Child2 derives from Child1

Then you go:

Then it will call Child1’s anotherPublicMethod

Cascade – every inheritance node needs to run

If you want a certain method tor un from Base to Child1, to Child2, make sure you use [super …] in the beginning of your call. A great example would be the init method.

Base’s init

Child1’s init

Child2’s init

Allocating a Child2 object

would have the result:

— Base.m – creating Base object —
— Child1.m, init Child1 object —
— Child2.m – init Child2 object

Child2’s init calls [super init], which is Child1’s init
Child1’s init calls [super init], which is Base’s init
Base’s init calls [super init], which is NSObject’s init

When NSObject’s init returns, our execution moves forward and displays Base init method’s log
When Base init method returns, our execution moves forward and displays Child1’s init method’s log
When Child1’s init method returns, execution moves forward and displays Child2’s init method’s log.

Hence, we have

— Base.m – creating Base object —
— Child1.m, init Child1 object —
— Child2.m – init Child2 object