• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

significance of private with final modifier method

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic