Overriding a super class’s instance variables

He perhaps meant to try and override the value used to initialize the variable.
For example,

Instead of this (which is illegal)

public abstract class A {
    String help = "**no help defined -- somebody should change that***";
    // ...
}
// ...
public class B extends A {
    // ILLEGAL
    @Override
    String help = "some fancy help message for B";
    // ...
}

One should do

public abstract class A {
    public String getHelp() {
        return "**no help defined -- somebody should change that***";
    }
    // ...
}
// ...
public class B extends A {
    @Override
    public String getHelp() {
        return "some fancy help message for B";
    // ...
}

Leave a Comment