I just tried the exumalator's question of the day, and I have a question:
1. char h = 1; //on the line before the System.out.println statement. 2. static char h = 1; //On the line before the System.out.println statement 3. char h = 1;//On the line before the main method 4. static char h = 1;//On the line before the main method
The answer is listed as 1 and 4, which is fine, but I also think 2 is also an option. Can't you put static variables inside a static method?
Peter MacMillan
Ranch Hand
Joined: Jun 23, 2006
Posts: 34
posted
0
Originally posted by J Brewer: Can't you put static variables inside a static method?
No. Only the final modifier is allowed.
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
posted
0
No, static is a modifier you use on class variables and methods.
J Brewer
Ranch Hand
Joined: Jul 10, 2006
Posts: 46
posted
0
Well, that's what I thought at first. But then I saw one source that said 'you can have static variables inside a static method', so I wasn't sure.
Thanks!
Sujittt Tripathyrr
Ranch Hand
Joined: Jun 21, 2006
Posts: 96
posted
0
Hi
Here I have one doubt that in general method we can put static variable but in static method why not.
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
posted
0
There is only one modifier can be used by local variables that is final modifier.
Suhas Wadadekar
Ranch Hand
Joined: May 16, 2006
Posts: 95
posted
0
i agree with Owen.....we cannot have any other variable modifier inside a method. As listed in the rules governing staic declarations in K & B book, I think that anything that is method-local cannot be static.