It's not overriding the method. Private methods are not inherited and are not accessible by or visible to subclasses. Having both private
and final
on a method is rather silly.
Your Clidlet
class does not actually override that method from Clidder
, it simply defines a new method named flipper()
that is unrelated to the one in Clidder
.
This is precisely why the @Override
keyword exists. Use it, and it will prevent you from making subtle errors like this, e.g. the following code would fail to compile since flipper()
isn't actually overriding anything:
public class Clidlet extends Clidder {
@Override public final void flipper() {
System.out.println("Clidlet");
}
public static void main(String[] args) {
new Clidlet().flipper();
}
}
That's a very poor example for them to have put in that book, unless it's specifically an example of subclasses not having access to base private methods.