Не совсем точно, что вы делаете, но ваши String a
члены private static
члены класса, а не отдельных объектов.
Если вы сделали String a
членом объекта, а не класса, вы можете переопределить значение при создании дочернего класса:
U:\>jshell
| Welcome to JShell -- Version 12
| For an introduction type: /help intro
jshell> class SuperClass {
...> protected final String a;
...>
...> protected SuperClass(String _a) {
...> a = _a;
...> }
...>
...> public SuperClass() {
...> this("Super");
...> }
...>
...> public void superMethod() {
...> System.out.println("SuperMethod: "+a);
...> }
...> }
| created class SuperClass
jshell> class ChildClass extends SuperClass {
...> public ChildClass() {
...> super("Child");
...> }
...> }
| created class ChildClass
jshell> var s = new SuperClass();
s ==> SuperClass@4566e5bd
jshell> var c = new ChildClass();
c ==> ChildClass@ff5b51f
jshell> s.superMethod();
SuperMethod: Super
jshell> c.superMethod();
SuperMethod: Child
Обновление
Теперь, когда мы знаем ваш реальный вариант использования (из комментария ниже), то, что вы хотите реализовать, довольно просто:
class SuperClass {
private final static Logger LOG = Logger.getLogger(SuperClass.class);
protected Logger getLogger() { return LOG; }
public void superMethod(){
getLogger().info("superMethod() called.");
}
}
class ChildClass extends SuperClass {
private final static Logger LOG = Logger.getLogger(ChildClass.class);
@Override
protected Logger getLogger() { return LOG; }
}
public class Main {
public static void main(String[] args) {
SuperClass s = new SuperClass();
ChildClass c = new ChildClass();
s.superMethod(); // Message logged to SuperClass.LOG
c.superMethod(); // Message logged to ChildClass.LOG
}
}