from what the
java compiler is telling me it seems static methods do get inherited and that one can override a static method :roll:
1. if you run the program below, you will see that static method are not polymorphic
2. in class foo, if you add final to the who method you will get an error, which seems to indicate static methods do get inherited
Compiler error test.java:1: who() in foobar cannot override who() in foo; overridden method is
static final
public class test{ static public void main(
String[] arg) {
test t = new test(); t.showWhoCalled(new foo()); t.showWh
oCalled(new foobar()); } void showWhoCalled(foo f) {
System.out.println(f.who()); }}class foo{ final static String who() { retu
rn "foo"; }}class foobar extends foo{ static String who() { return "foobar"; }
}
3. if you removed the keyword static from the who() method in class foo and foobar, you will see the polymorphic behaviour
(*) conclusion: class static methods to get inherited, can be overridden but are not polymorphic
[ May 19, 2003: Message edited by: Rajinder Yadav ]