Bhushan Bhawsar wrote:We override a method when we need to provide a new implementation in our subclass, but in the first example where the classes are in different packages, the subclass has no information that there is method m () present in the super class (due to access modifiers used), so it cannot override it. We cannot override something which we can not see i.e not inherited. If we write a method m() in subclass then it will be a new method in class with no override.
Right. And, as Henry said,
that's how Java defines it.
But TBH, it also just makes sense. If everything can be overridden, then what's the point of having a
private (or indeed default) qualifier for a method?
Perhaps a more pertinent question: When was the last time you overrode a
private method in C++, and
why did you do it? I was a C++ programmer for 3 years or so, and it never even occurred to me that such a facility might
exist - indeed, the whole idea of a
private virtual method seems nonsensical to me; except possibly in a nested class.
Winston