Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final methods

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen when we mark a method as final
 
sujith Acharya
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can not override the method in its child class
 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sujith Acharya wrote:you can not override the method in its child class


It means that same as marking private??
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really a basic question. Moving to Beginning Java.
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aruna Balasuriya wrote:It means that same as marking private??
No
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic