Why cant i declare a static variable in a static function without final. | Sololearn: Learn to code for FREE!
0

Why cant i declare a static variable in a static function without final.

If the same static variable is declared outside the static function then its is ok but when it is declared inside then the error occurs "illegal modifier for parameter i; only final is permitted", why is this so??

25th Mar 2017, 7:49 PM
pranjal kumar
pranjal kumar - avatar
1 Answer
+ 13
static means that the variable belongs to the class. If a variable is static you can access it without instantiating an object of the class. That's why you can't use static inside a method.
26th Mar 2017, 4:08 PM
Tashi N
Tashi N - avatar