why static function does not have any static local variable in java -
following java program fails in compilation error “static local variables not allowed”
class myclass { public static void main(string args[]) { system.out.println(myfun()); } static int myfun() { static int var= 10; return var += 1; } }
if want static variable (whose value reused in consecutive calls static method), declare outside method :
static int var= 10; static int myfun() { return var += 1; }
local variables can't static, since local variable exists within scope of single execution of method.
Comments
Post a Comment