• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch

 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why this program gives compile time error.
Stating illegal start of expression .
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't think you can declare a static variable inside a method. move it outside of the main method, and it compiles.
 
Trevor Whitehead
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
local variables can only be marked final
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all.Yes local variable can be marked only final.
 
Aruna Agrawal
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic