aspose file tools*
The moose likes Beginning Java and the fly likes Final methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Final methods" Watch "Final methods" New topic
Author

Final methods

Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
What will happen when we mark a method as final
sujith Acharya
Ranch Hand

Joined: Dec 25, 2006
Posts: 60
you can not override the method in its child class
Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
sujith Acharya wrote:you can not override the method in its child class


It means that same as marking private??
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Aruna Balasuriya wrote:
It means that same as marking private??


Recommended reading
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
http://java.sun.com/docs/books/tutorial/java/IandI/final.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Really a basic question. Moving to Beginning Java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Aruna Balasuriya wrote:It means that same as marking private??
No
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Aruna Balasuriya wrote:What will happen when we mark a method as final

When you mark a method final you are saying that there would be no alternate implementations of the method. Usually, alternate implementations are provided by overriding the same method in sub-classes so this means you cannot override a final method.
Also, there could be other optimizations done at different levels once you provide that sort of commitment (for e.g. a compiler can inline your method code).

It means that same as marking private??

When you mark your method private you are limiting the visibility or accessibility of your method. The method will not be visible, inherited by your sub classes.

I think, you would agree that limiting accessibility and controlling alternate implementations are two different types of control.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
 
wood burning stoves
 
subject: Final methods