RE: what type of access specifiers can we use for local variables?
hi there the type of access specifiers depend purely on how is the logic of your programme oriented:
CASE1:the best approach that is suggested by most of the top programmers have been to make your variables as private which is best for the purpose of security as well.
CASE2:suppose if you want that when you are instantiating your class then one particular method of that class should not have all the variables accessible to it but only few that you have declared in the beginning of the class then declare that method as well as the variable that you wnt to be accessible as static and only that variable becomes accessible for that method.
CASE3:if you want that whatever happens you don't want any of a particular variable to change in any of the case then declare it FINAL.
RE: what type of access specifiers can we use for local variables?
Local Variables and Access Modifiers Can access modifiers be applied to local variables?
NO!
There is never a case where an access modifier can be applied to a local variable so watch out for code like the following:
class Foo { void doStuff() { private int x 7; this.doMore(x); } } You can be certain that any local variable declared with an access modifier will not compile. In fact there is only one modifier that can ever be applied to local variables—final.
RE: what type of access specifiers can we use for local variables?
Local variables (including formal parameters) are visible only in the method constructor or block in which they are declared. Access modifiers (private public ...) can not be used with local variables. All local variables are effectively private to the block in which they are declared. No part of the program outside of the method / block can see them. A special case is that local variables declared in the initializer part of a for statement have a scope of the for statement.