jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "switch" Watch "switch" New topic


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

Joined: Oct 02, 2003
Posts: 11952

i don't think you can declare a static variable inside a method. move it outside of the main method, and it compiles.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Trevor Whitehead

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
[ 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
I agree. Here's the link: http://aspose.com/file-tools
subject: switch
It's not a secret anymore!