在Java中继承静态变量

Sap*_*Sun 4 java polymorphism inheritance static static-variables

我想要进行以下设置:

abstract class Parent {
    public static String ACONSTANT; // I'd use abstract here if it was allowed

    // Other stuff follows
}

class Child extends Parent {
    public static String ACONSTANT = "some value";

    // etc
}
Run Code Online (Sandbox Code Playgroud)

这在Java中可行吗?怎么样?如果我可以避免它,我宁愿不使用实例变量/方法.

谢谢!

编辑:

常量是数据库表的名称.每个子对象都是一个迷你ORM.

ste*_*tew 18

你无法完全按照自己的意愿去做.也许可接受的折衷方案是:

abstract class Parent {
    public abstract String getACONSTANT();
}

class Child extends Parent {
    public static final String ACONSTANT = "some value";
    public String getACONSTANT() { return ACONSTANT; }
}
Run Code Online (Sandbox Code Playgroud)