(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 ]]

发表评论

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

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 登出 /  更改 )

Google photo

您正在使用您的 Google 账号评论。 登出 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 登出 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 登出 /  更改 )

Connecting to %s