> I think static methods don't show polymorphic behavior because static
> methods are bound to classes.
Yep.
> But, when f1 is called from a reference to an object of base, then f1
> in base class is called and if f1 is called from reference to an object
> of derived, then f1 in derived class is invoked.
First of all, it's moderately broken (but technically legal) to call f1
using a reference in the first place. The compiler in Eclipse can be
set up to give you an error or warning when you do it, and CheckStyle
can do the same. These are good things. The correct way to call f1 is
as follows:
BaseC1.f1(); OR
DerivedC1.f1();
In either case, it's clear which of the two methods is being called.
Remember, just say not to calling static methods using a reference.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Venkatesh - 20 Apr 2006 05:26 GMT
Hi Chris,
Thanks for your note. You are right. Even I always ensure that static
functions are called using the class name and not any reference. I was
just trying to see if calling from references by any chance makes the
functions show polymorphic behavior. But, this behavior was not shown
....
Thank you,
Venkatesh
> But, when f1 is called from a reference to an object of base, then f1
> in base class is called and if f1 is called from reference to an
> object
> of derived, then f1 in derived class is invoked.
Doesn't that depend on what the compile-time type of each respective
object was?
It's a misconception that a static method is *ever* "called from a
reference to an object." That simply never happens. If you
syntactically call a static method on an object reference, it is
compiled as a static method call on whatever class that object happened
to be at compile time.
Eric Sosman - 19 Apr 2006 20:02 GMT
James McGill wrote On 04/19/06 14:12,:
>>But, when f1 is called from a reference to an object of base, then f1
>>in base class is called and if f1 is called from reference to an
[quoted text clipped - 9 lines]
> compiled as a static method call on whatever class that object happened
> to be at compile time.
One of the clearest demonstrations of this point
is to set the reference to null before using it to
call the static method. Since the method actually
does get called even though there's no object lying
around, it's obvious that the run-time type of the
object has nothing to do with the matter. All that
counts is the compile-time type of the reference.

Signature
Eric.Sosman@sun.com
Andrew McDonagh - 19 Apr 2006 23:08 GMT
> James McGill wrote On 04/19/06 14:12,:
>>
[quoted text clipped - 19 lines]
> object has nothing to do with the matter. All that
> counts is the compile-time type of the reference.
Yep - and thankfully now most IDEs will warn (at least) that you are
caling a static method on an object instance, rather than a class.