GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 463 of 502    Print  
what type of access specifiers can we use for local variables?

  
Total Answers and Comments: 8 Last Update: August 18, 2009     Asked by: naggeek 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: keshavgopal.se
 
No private access modifier cant be used only access specifier that can be used is "final"
 and thats final.

Above answer was rated as good by the following members:
interviewprep9, r.praveenkumar, swpnl_ptl, james.vinett, bino75, coolpintu
December 24, 2007 03:58:12   #1  
ksmbasha Member Since: December 2007   Contribution: 2    

RE: what type of access specifiers can we use for local variables?
private
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
January 09, 2008 01:00:21   #2  
keshavgopal.se Member Since: December 2007   Contribution: 5    

RE: what type of access specifiers can we use for local variables?
No private access modifier cant be used only access specifier that can be used is "final"
and thats final.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
February 11, 2008 06:08:57   #3  
sampra Member Since: February 2008   Contribution: 278    

RE: what type of access specifiers can we use for local variables?
we can use only this and final
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
May 12, 2008 15:24:15   #4  
tpran1685 Member Since: May 2008   Contribution: 3    

RE:
There are only four access specifiers in Java
public private protected default(no specifier) and none of these can be used on a local variable.

 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
June 09, 2008 11:41:33   #5  
vegetto Member Since: June 2008   Contribution: 10    

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.


 
Is this answer useful? Yes | No
July 08, 2008 02:44:57   #6  
Naveenjavasun Member Since: July 2008   Contribution: 6    

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.

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
August 03, 2008 02:43:59   #7  
er.mukesh_208 Member Since: May 2008   Contribution: 3    

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.
 
Is this answer useful? Yes | No
August 18, 2009 03:58:24   #8  
Sarje Member Since: August 2009   Contribution: 62    

RE: what type of access specifiers can we use for local variables?
Local variable cannot be modified using any of the acceess specifiers means you can not write private or protected or public before them.

Local variables are by default (implicitly) private no need to make it explicitly private or protected or public otherwise it won't compile.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape