Re: Static methods overridden !!
- From: "Ravi" <v.r.sankar@xxxxxxxxx>
- Date: 25 Mar 2007 19:50:36 -0700
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.
My understanding of overriding is as follows. (Not polymorphism , just
sticking to overriding)
Class Super {
public void method1(){}
}
Class DerivedOne extends Super {
}
Class DerivedTwo extends Super {
public void method1(){}
}
public Class OverrideDemo {
public static void main(String a[]) {
new DerivedOne().method1(); //calls the Super class method1()
new DerivedTwo().method1(); //calls the DerivedTwo class method1()
}
}
I am not talking about polymorphism here, just overriding. If you
observe carefully, then the behavioiur of statis methods is exactly
similar. Assume that the method1 is static.
DerivedOne.method1() ; //will call Super static method method1.
DerivedTwo.method2(); //will call DerivedTwo static method method1.
Technically speaking static methods ARE OVERRIDDEN, not at the object
level ofcourse at the class level as invocation of statics is not
object dependent. Also, we cannot take the advantage of polymorphism
in case of the static methods but thats not the point. Static methods
are overridden.
Does my argument make sense?
Regards,
Ravi
.
- Follow-Ups:
- Re: Static methods overridden !!
- From: Chris Uppal
- Re: Static methods overridden !!
- From: Michael Rauscher
- 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
- Re: Static methods overridden !!
- From: Lew
- Static methods overridden !!
- Prev by Date: JPanel this reference escape in constructor.
- Next by Date: Re: create database
- Previous by thread: Re: Static methods overridden !!
- Next by thread: Re: Static methods overridden !!
- Index(es):
Relevant Pages
|