Ok, it happens to be more confusing than I thought but I still think I'm right. When you override a method you generally want
polymorphism to work. This doesn't happen in case of "overriding" of static methods. Try to run these two examples:
1. "Overriden" static
<pre>
public class StaticOverride
{
public static void foo(String s)
{
System.out.println(s);
}
public void bar()
{
foo("some_string");
}
public static void main(String[] a)
{
StaticOverride so = new StaticOverride1();
so.bar();
}
}
class StaticOverride1 extends StaticOverride
{
public static void foo(String s)
{
System.out.println("In child class " + s);
}
}
</pre>
2. Overriden normal
<pre>
public class StaticOverride
{
public void foo(String s)
{
System.out.println(s);
}
public void bar()
{
foo("some_string");
}
public static void main(String[] a)
{
StaticOverride so = new StaticOverride1();
so.bar();
}
}
class StaticOverride1 extends StaticOverride
{
public void foo(String s)
{
System.out.println("In child class " + s);
}
}
</pre>
After you run it 1 should output:
some_string
and 2 should print:
In child class some_string
This proves that polymorphism doesn't work for "overriden" static methods. In other words, runtime type of an object doesn't define which method will be actually invoked in case of static "overriden" methods. Hopefully I didn't confuse you and myself. Other opinions are welcome.
--VG
[This message has been edited by Vlad G (edited January 03, 2001).]