Re: Static methods overridden !!
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 25 Mar 2007 16:39:05 -0400
Ravi wrote:
Well, the class doesn't have the method at all ! Please refer the
original code again. CowTest class doesn't have saySomething method at
all . It has saySomething1 (1 (one) extra in the end, may be I should
have made this more clearly differentiating). I am not referring the
objects here and I am clear on the fact that objects have nothing to
do with invocation of static methods.
The method-resolution mechanism moves up the inheritance hierarchy from the compile-time type to look for the first matching method. Since CowTest "is-an" AnimalTest, the invocation from CowTest can find the method in AnimalTest.
However, if CowTest did have a matching static method, it wouldn't override the superclass static method, it would hide the superclass static method. There is no polymorphism of static methods.
AnimalTest.saySomething() will never invoke CowTest.saySomething().
-- Lew
.
- Follow-Ups:
- Re: Static methods overridden !!
- From: Ravi
- Re: Static methods overridden !!
- References:
- Static methods overridden !!
- From: Ravi
- Re: Static methods overridden !!
- From: Daniel Pitts
- Re: Static methods overridden !!
- From: Ravi
- Re: Static methods overridden !!
- From: Eric Sosman
- Re: Static methods overridden !!
- From: Ravi
- Re: Static methods overridden !!
- From: Joshua Cranmer
- Static methods overridden !!
- Prev by Date: Re: PayPal
- Next by Date: Re: Reflection: Instantiate All Classes in a Package?
- Previous by thread: Re: Static methods overridden !!
- Next by thread: Re: Static methods overridden !!
- Index(es):
Relevant Pages
|