Local variables in java
Posted
by Mandar
on Stack Overflow
See other posts from Stack Overflow
or by Mandar
Published on 2010-05-16T15:55:42Z
Indexed on
2010/05/16
16:10 UTC
Read the original article
Hit count: 299
Hello ,
I went through local variables and class variables concept.
But I had stuck at a doubt
" Why is it so that we cannot declare local variables
as static
" ?
For e.g
Suppose we have a play( ) function :
void play( )
{
static int i=5;
System.out.println(i);
}
It gives me error in eclipse : Illegal modifier for parameter i
;
I had this doubt because of the following concepts I have read :
- Variables inside method : scope is local i.e within that method.
- When variable is declared as static , it is present for the entire class i.e not to particular object.
Please could anyone help me out to clarify the concept.
Thanks.
© Stack Overflow or respective owner