| Author |
switch
|
meena latha
Ranch Hand
Joined: Jan 24, 2005
Posts: 219
|
|
Why this program gives compile time error. Stating illegal start of expression .
|
 |
Animesh Shrivastava
Ranch Hand
Joined: Jul 19, 2004
Posts: 298
|
|
U cant have static variable inside a static method The variable i is declared to be static final Thats why i guess its a compiler error.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10043
|
|
|
i don't think you can declare a static variable inside a method. move it outside of the main method, and it compiles.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Trevor Whitehead
Greenhorn
Joined: Oct 16, 2002
Posts: 16
|
|
|
local variables can only be marked final
|
 |
meena latha
Ranch Hand
Joined: Jan 24, 2005
Posts: 219
|
|
|
Thanks to all.Yes local variable can be marked only final.
|
 |
Aruna Agrawal
Ranch Hand
Joined: Jan 27, 2005
Posts: 66
|
|
Why did the Java Designers didnt allow static variables in static methods. If i want that variable value persist across different calls to the method and at the same time hide the variable from other methods in the class , there is no way out in java. Please clarify the design issue involved... i guess they didnt want the method to maintain any state of its own. am i right .. thanks for reading aruna [ March 06, 2005: Message edited by: Aruna Agrawal ]
|
 |
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
|
|
There is no concept of hiding between members of the same outer enclosing class. If you look at the rules for inner classes, you will see what I mean.
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
 |
|
|
subject: switch
|
|
|