Larry,
Sounds to me like you know way too much C++ implementation
technology for your own good! (-
I'm a Lisp refugee, I had
to struggle to remember about ctor's....
Anyway, I think this is all a great deal easier if you forget
about the compiler, focus on the IS-A semantics, and remember
that method dispatch is dynamic.
"this" is a symbol useable in source code to allow you to write
a reference to the current object. The current object is what it
is, no matter who is talking about him, and there is only one
object there, not one for Base and another for Extension.
The point of dynamic method dispatch is: given an individual,
and any valid invocation of a non-private method on it such as
this.add(...), you will get the same result no matter where
the invoking code came from. It might be in Base, or Extension,
or Object; it might be in a method, a constructor, or a static
initializer; it doesn't matter: the SAME THING happens.
That is what jumped out at me about your post:
you were looking for differences in behavior of "this"
depending on where it was used, but the whole point (to me) is
that you get the same behavior no matter where it is used.
You are used to reading "this.foo(...)" and thinking aha,
"this" gets me to the method-dispatch vector of the class
whose code I'm reading. No, no! The semantics of
Java is
more dynamic, halfway to lisp. "this" gets you the current
object, the INSTANCE, not any class or piece of a class.
Then method lookup starts at the class of which the current
object is an IMMEDIATE instance, and searches up the inheritance
hierarchy, and takes the first method that matches the signature
sought.
This is so, REGARDLESS of where in the inheritance hierarchy
the code appeared that invoked the method in the first place.
So FWIW, my advice is: try not to think about "this" as an
internal implementation handle on a dispatch vector. Think
about it as the object itself; that's the level of abstraction
at which it was intended to be taken, IMHO.
Of course, Java didn't go dynamic in any consistent fashion.
So fields aren't inherited like this, and constructors are
different yet again, and private methods are different,
and static methods too, etc.
These will probably seem natural to you (Larry) since they
are more compiler oriented, and more like C++. Really only
non-private method dispatch is fully dynamic in Java.
And finally -- lest you feel I'm raggin' on ya -- note that:
I missed the damn question myself. Too many different add's!
Got careless and read the add in the Base constructor as if
it was statically dispatched.
Oh well.
[This message has been edited by Jim Goodwin (edited September 18, 2000).]