+ 1
Why cant i change variable values of instance variable while we can change value of local variables of same variable in java?
class example{ int a=2; a=4; System.out.println(a); } output error<identifier> why?
2 odpowiedzi
+ 1
Its not like you cant, but those are reserved for defining your class instance variable, and method.
Btw if you want to do such an operation outside any method you can use anonymous block, simply {} without name
class Bar{
int a=2;
{
a=3;
}
}
+ 1
thanks your answer is "tasty".😋