• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final and protected method at the same time

 
marwen Bakkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
marwen Bakkar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It makes sense, thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic