Rob
SCJP 1.4
A method can be declared final to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override or hide a final method.
A private method and all methods declared in a final class (�8.1.1.2) are implicitly final, because it is impossible to override them.
Rob
SCJP 1.4
Originally posted by Corey McGlone:
Hmm...I'm going to split hairs here for a minute, but I'm sure you're all used to this by now...
Why are private methods considered "implicitly final?"
Note that a private method cannot be hidden or overridden in the technical sense of those terms. This means that a subclass can declare a method with the same signature as a private method in one of its superclasses, and there is no requirement that the return type or throws clause of such a method bear any relationship to those of the private method in the superclass.
Originally posted by Valentin Crettaz:
With this code if you have call like objBase.aMethod() it will be a compile time error. As compared to objBase.aMethod() which not only compiles but also invokes base class implementation of the method, making private a better candidate for "Non-Overridable methods". Do I have a valid point here?
This is not clear at all... First you say objBase.aMethod() will yield a compiler error and then it compiles fine bla bla bla...
Could you please explain further or correct the above explanations? Thanks
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|