| 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: 8430
|
|
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
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Really a basic question. Moving to Beginning Java.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32607
|
|
Aruna Balasuriya wrote:It means that same as marking private??
No
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
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] | [My Blog] | [Samuh Varta]
|
 |
 |
|
|
subject: Final methods
|
|
|