public class BaseClass {
public void start() {
// do something
}
}
public class ClassA extends BaseClass {
}
ClassA c = new ClassA();
c.start();
In the following code I want to use the start() method as it was defined in the super class, I have seen in a lot of other developer's codes that they override the method in the super class and then they call the super. is there a reason for that?
public class ClassA extends BaseClass {
@Override
public void start() {
super.start();
}
}
Clarity? Some developers feel it is clearer to show the method in the subclass. I disagree. It's redundant info.
At least since Java 5, you could add an @Override so the compiler will tell you if the signature changes/disappears.
Except for constructors. For constructors, you really do have to create your own with the same signature and delegate upwards. In this case, omitting isn't equivalent though.