Thomas G. Marshall said:
Michael Borgwardt coughed up:
{shrug} The *compiler* does everything.
You're right. What I really should have said was a "variable of reference
of any value", not object.
Basically, given the declaration & definition:
{Type} {Variable Name} = {reference};
*Regardless* of the value of {reference},
{reference}.{static id}
yields the same thing as
{Type}.{static id}
Which is something I've always thought sloppy about Java.
I sorta object to your using {Type}. etc. The way I teach it would seem to
eliminate the confusion: Ahem....
Data is referred to based on the class of the reference variable.
Methods are referred to based on the class of the object.
This means that if a reference variable is declared as class Dummy, then
regardless of whether it addresses an actual object or not (i.e. is Null)
any data referred to with that reference will be located with reference to
the Class, in this case Dummy. So whether it is null, addresses a valid
Dummy object, or a derived class of Dummy it will refer to the static data
in Dummy, because it is a Dummy reference.
Methods work differently, using dynamic dispatch to find the code to be
executed -- based on the object that is being referred to. So if the
reference variable contains null you get a null pointer exception. If the
reference variable refers to an existing object, that object's loaded
methods are searched, proceeding up the inheritance chain if necessary to
find the code to execute. Hence, polymorphism. Even if the reference is
declared as a Base class, it still uses the object's methods.
[This phrasing eliminates my having to go into static/dynamic resolution of
identifiers by the compile process. They are, after all, beginners.]
Make corrections as appropriate.....