Static methods overridden !!
- From: "Ravi" <v.r.sankar@xxxxxxxxx>
- Date: 25 Mar 2007 09:55:26 -0700
Hi,
Consider the following piece of code
class AnimalTest {
public static void saySomething() {
System.out.println(" AnimalTest!");
}
}
class CowTest extends AnimalTest {
public static void saySomething1() {
System.out.println(" CowTest!");
}
public static void main(String[] args) {
AnimalTest[] animals = { new AnimalTest(), new CowTest() };
for (AnimalTest a : animals) {
a.saySomething();
}
new CowTest().saySomething();
}
}
Interestingly it prints out AnimalTest! thrice. I am wondering how did
it compile as CowTest doesn't have the method saySomething. Does the
static method got carried over to the subclass??
Regards,
Ravi
.
- Follow-Ups:
- Re: Static methods overridden !!
- From: Daniel Pitts
- Re: Static methods overridden !!
- Prev by Date: Re: Choices - moving to Java environment
- Next by Date: Re: SyncronizingProxyFactory: Pattern or antipattern?
- Previous by thread: Choices - moving to Java environment
- Next by thread: Re: Static methods overridden !!
- Index(es):