Given the following classes:
public abstract class Super {
protected static Object staticVar;
protected static void staticMethod() {
System.out.p
Be careful in your title, static fields and methods are NOT inherited. This means that when you comment staticMethod()
in Sub
, Sub.staticMethod()
actually calls Super.staticMethod()
then Sub
static initializer is not executed.
However, the question is more interesting than I thought at the first sight : in my point of view, this shouldn't compile without a warning, just like when one calls a static method on an instance of the class.
EDIT: As @GeroldBroser pointed it, the first statement of this answer is wrong. Static methods are inherited as well but never overriden, simply hidden. I'm leaving the answer as is for history.