0
Variable confusion
Variable int x passed as parameter to method1 is local or instance? https://code.sololearn.com/cZLYp1o890D4/?ref=app
3 Answers
+ 4
As you can see in the code you posted the value can be changed for static members. I think you're confusing it with final. They do different things and a member can actually have both modifiers applied to it. For instance:
static final int x = 5;
would be an int thats value can't be changed but would still be shared amongst all instances of the class.
+ 3
The x passed to the method with a value of 5 is local and is never used in the method. The static int x belongs to the class and shares its value across all instances of the class and any change made to its value from any instance, changes it for all instances of the class.
0
ChaoticDawg can we change value of static variable int x which is class variable? I have heard static values cannot be changed?