File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes final and protected method at the same time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "final and protected method at the same time" Watch "final and protected method at the same time" New topic
Author

final and protected method at the same time

marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
Hi,

I thought a final method can not be overridden and thus it would make no sense to write a method with the final and protected modifiers at the same time.
But I stumbled on this code from "Java concurrency in practice" :




Does anyone one what does this mean? I doubt it's a mistake as it did not occur just once.
Thanks.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4540
    
    5

A protected method is inherited, and can be invoked from, a subclass. The way I see it, the design decision behind making a method both protected and final is: final, so the implementation cannot be changed, and protected, so that it cannot be called from anywhere outside the inheritance hierarchy.

There are protected final methods in the JDK classes. An example: the defineClass overloads in SecureClassLoader and ClassLoader


luck, db
There are no new questions, but there may be new answers.
marwen Bakkar
Ranch Hand

Joined: Jan 28, 2010
Posts: 84
It makes sense, thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final and protected method at the same time