wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes significance of private with final modifier method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "significance of private with final modifier method" Watch "significance of private with final modifier method" New topic
Author

significance of private with final modifier method

Pradeep Kumar
Ranch Hand

Joined: Sep 08, 2006
Posts: 108

Hi ranchers,

A private method in a class is only visible inside the declaration class and cannot be overridden in the subclass.

Then what is the significance of having a private method with a final modifier? As far as I know there is no significance. If there is any specific significance kindly let me know.


Thanks and Regards, Pradeep Kumar
SCJP 1.6, SCWCD 5.0
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

There is no special significance, and indeed, because methods that are private are only visible to the class itself and are not inherited by subclasses, it doesn't make much sense to make private methods final.

Note that for instance variables it's different, because the meaning of the word "final" is different: it means the value can't be changed once it's initialized (it doesn't have anything to do with inheritance).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Note that inner classes can see eachother's privates, and those of the containing class. Therefore you could cook up a scenario where an inner class (which was also a subclass of another inner class) was blocked from overriding a final private method. That's awfully far-fetched, though, and I think "there's no purpose for it" is a fine answer in general.


[Jess in Action][AskingGoodQuestions]
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I just finished a project that has your exact example Ernest, except with an attribute and a class
The outer class is called SymbolTable and the inner nested class is called TableEntry, and the symbol table is made up of entries. SymbolTable only has one attribute which is a private final HashMap. And the only way I wanted the HashMap to be modified was from the SymbolTable class

Shortened Code Below:


Hope this helps,
Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Hunter, your example has a private final inner class TableEntry and a private final instance variable table but there is no private final method, which was what the original question was about.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: significance of private with final modifier method
 
Similar Threads
Benefits of making Private methods as final?
private final method??
Significance of 'final' modifier
private class
static and final methods