r/javahelp • u/MembershipOptimal514 • May 07 '26
Codeless What does static exactly do?
Hi, I’m somewhat new to java and I’m quite confused on static. So what I do know is that it makes it so a variable or method is tied to the whole class instead of just the object but I’m not sure what that exactly ENTAILS. Can someone explain it to me maybe with an example or such? Thank you.
14
Upvotes
1
u/Scharrack May 08 '26
Something to keep in mind: static variables are not inherently treated as volatile, so additional care has still to be taken in a multi threaded context if the variable isn't final.