(subClassObj(superClassObj))-> onion

Best 1-word glue to tie up constructor chain-reaction, object inheritance, overriding, dynamic binding…. is onion

To drive home the concept, think of any java object as an onion. If C extends B extending A extending Object, then an C obj wraps a B obj, enclosing an A obj, containing an Object obj. There’s always an Object.java instance at the core, inside the innermost onion layer.

In the constructor call stack, C() calls B(), which calls A(), which calls Object(). The callstack looks exactly like an onion. First statement in ANY constructor is always an (implicit or explicit) call to super(). No exception.

Dynamic binding explained by Mr. Onion — If an ancestor method m() is overriden (must be non-static) by every descendant, then a call to m() binds (only at runtime, never compile-time) to the outermost onion layer, ie the most specific implementation of m(). This is regardless of what you put before “. m()” — type_a_var.m() or type_b_var.m() all binds to the m() implementation in C.java. See p 45 [[ Java precisely ]]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s