• Post Reply Bookmark Topic Watch Topic
  • New Topic

Final Keyword  RSS feed

 
rizwana mujawar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant i mark my constructor as final. I can understand that it cant be marked as abstract or static. Because it cant be overridden(hence not abstract) and it has be associated with instantiation(hence not static)... But why not final.. Dont know the reason.... Anyone knows the reason....?
Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors can't be overridden or inherited. What's the point in marking them final?
 
rizwana mujawar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Constructors can't be overridden or inherited. What's the point in marking them final?

Then mark it final... Because whole funda of final keyword is restriction to overriding and inheritance.... If dont the constructor to be inherited or overridden then you should mark them final...? iam still confused and not satisfied with reason...
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rizwana mujawar wrote:Then mark it final... Because whole funda of final keyword is restriction to overriding and inheritance.... If dont the constructor to be inherited or overridden then you should mark them final...? iam still confused and not satisfied with reason...

Again, a constructor cannot be inherited, or overridden. So, what's the point of making them final? We make a method final if we want to restrict overriding of it. Constructor already have this property.

Secondly, you can only mark variables,methods and classes as final. Constructor is not a method.

I hope this helps.
 
Ernesto Arroyo
Greenhorn
Posts: 11
Java Objective C Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the point here is also that a constructor is not a method (does not have a return for example) so you dont have to see a constructor like a method.
final is not used (nor allowed) in constructor to avoid confusion: constructors are final, always.
 
rizwana mujawar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guy's for clearing my confusion...
Regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!