Is it possible to overwrite a static method in parent class?
Posted
by MartinDenny2069
on Stack Overflow
See other posts from Stack Overflow
or by MartinDenny2069
Published on 2010-05-14T02:03:17Z
Indexed on
2010/05/14
2:14 UTC
Read the original article
Hit count: 326
I have a static method defined in a base class, I want to overwrite this method in its child class, is it possible?
I tried this but it did not work as I expected. When I created an instance of class B and invoke its callMe() method, the static foo() method in class A is invoked.
public abstract class A {
public static void foo() {
System.out.println("I am base class");
}
public void callMe() {
foo();
}
}
Public class B {
public static void foo() {
System.out.println("I am child class");
}
}
© Stack Overflow or respective owner