d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Final Keyword
Add Reply New Topic New Poll
Member
Posts: 31,375
Joined: Mar 25 2009
Gold: 15.00
Jun 9 2019 09:43pm
is there a reason to use final keyword on methods of a class, that have no subclasses? I mean it can't be overriden anyway if it has no subclasses, so is there even a reason to use final?



/me edit, also i know what static does for methods and variables, but is there such a thing as a static class? if so, what does it do? THanks!!

This post was edited by ferf on Jun 9 2019 09:53pm
Member
Posts: 8,992
Joined: Mar 24 2013
Gold: 18,115.00
Jun 11 2019 04:23am
There is a reason. Basically, if you develop a project and, let's say, some person X would like to use your code, then you - as a project developer and author of this code - should decide, how to use this code and how should it work.
So even if you don't extend class Foo in your project personally, some guy X might do so. However, there may be some problems with such an inheritance and you decide that no one should extend this class (or override some method).
That's why you tag a class/method with final keyword.
Member
Posts: 31,375
Joined: Mar 25 2009
Gold: 15.00
Jun 11 2019 11:46am
Quote (pzold @ Jun 11 2019 06:23am)
There is a reason. Basically, if you develop a project and, let's say, some person X would like to use your code, then you - as a project developer and author of this code - should decide, how to use this code and how should it work.
So even if you don't extend class Foo in your project personally, some guy X might do so. However, there may be some problems with such an inheritance and you decide that no one should extend this class (or override some method).
That's why you tag a class/method with final keyword.


Thanks!! :)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll